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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/babybabyup/article/details/84316655

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文件,当然觉得没错误了。。

猜你喜欢

转载自blog.csdn.net/babybabyup/article/details/84316655