1. 程式人生 > >android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating c

android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating c


android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.v7.app.AlertController.RecycleListView
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.v7.app.AlertController.RecycleListView
 Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.example.nick.rec-RQvjKMWoE8TX95M1ypAYbg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.nick.rec-RQvjKMWoE8TX95M1ypAYbg==/lib/x86, /system/lib]]
 

問題描述
在學android課程時,學到了RecyclerView 控制元件時,被一個小小的錯誤困惑兩天之久。問題描述如上所敘述。

  • 當我遇到這個問題首先是覺得自己的程式碼敲錯了,在java中引入了不同包的同名類,但是我檢查了好半天,又自己重新開專案去測試,問題仍然沒有得到解決。
  • 我按著書上的程式碼敲來的,一模一樣為什麼就不能執行呢?
  • 然後我就覺得是我的android studio出問題了 又重新下載安裝等等一系列 虛擬機器測試,真機測試等等的都換過幾次。
  • 最後這個錯誤仍然是巋然不動。
  • 終於在一個不起眼的地方對xml檔案稍微關注了一下,我一拍腦門,啊呀,xml引用的控制元件和我java檔案裡的import一樣的麼?

我的java檔案匯入

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

但是xml呢?

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--<LinearLayout-->
        <!--android:layout_width="wrap_content"-->
        <!--android:layout_height="wrap_content">-->
        <!--<TextView-->
            <!--android:id="@+id/t"-->
            <!--android:layout_width="wrap_content"-->
            <!--android:layout_height="wrap_content"-->
            <!--android:text="@string/app_name"/>-->

    <!--</LinearLayout>-->
    <android.support.v7.app.AlertController.RecycleListView
        android:id="@+id/recycler_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    </android.support.v7.app.AlertController.RecycleListView>

</android.support.constraint.ConstraintLayout>

修改xml檔案即可:

<android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>

ok 問題解決,原來"android.support.v7.app.AlertController.RecycleListView"是在xml檔案中,找了兩天的java檔案,當然覺得沒錯誤了。。