Error inflating class RecyclerView

后端 未结 5 1441
野性不改
野性不改 2020-12-17 08:57

So my code simply makes a list of CardViews using RecyclerView. Upon running my code i kept getting a weird error claiming there was an error in my xml. After tinkering for

相关标签:
5条回答
  • 2020-12-17 09:03

    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!

    0 讨论(0)
  • 2020-12-17 09:09

    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
    
    0 讨论(0)
  • 2020-12-17 09:09

    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.

    0 讨论(0)
  • 2020-12-17 09:16

    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.

    0 讨论(0)
  • 2020-12-17 09:17
    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

    0 讨论(0)
提交回复
热议问题