Error inflating class RecyclerView

北城余情 提交于 2019-11-29 05:26:26

RecyclerView is not included in base Android framework, only widgets in base Android framework (like ListView, GridView etc) can be specified in layout without full namespace. RecyclerView is part of recyclerview-v7 support library.

You should add the RecyclerView in the XML in this way:

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

</android.support.v7.widget.RecyclerView>

Hope it helps!

I meet this problem today. And solved it.

first step:keep the support-libs you used are same version

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'

second step:you should add recyclerView to your proguard files

-keep class android.support.v7.widget.** {*;}
// I`ve just keep all widgets

Make sure to include before you add RecyclerView to your XML

compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'

If you created RecyclerView in your XML before adding these dependencies, to make it work you should remove (comment) your recycler view, build project without it and then add it back. Otherwise it still shows Inflate exception in binary XML line #n.

  1. Check reference in build.gradle
  2. In your layout xml file be, write your RecyclerView component's name as a whole with its package like that android.support.v7.widget.RecyclerViewnot like RecyclerView

now ready to lunch. Good trails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!