Error inflating class and android.support.v7.widget.CardView

后端 未结 15 1601
-上瘾入骨i
-上瘾入骨i 2020-11-27 20:47

I want to use CardView in my project, but when I run my application, I get the following error. I\'m using Eclipse.

Error: Error inflating clas         


        
15条回答
  •  迷失自我
    2020-11-27 21:39

    I guess your problem is not within your xml layout, but your build.gradle settings.

    When you want to use support library for Recyclerview or CardView in lower API devices, you not only needs to import the v7 library, but also needs to import Recycler View and Card View support independently.

    Like this:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:21.0.+'
        compile 'com.android.support:cardview-v7:21.0.+'
        compile 'com.android.support:recyclerview-v7:21.0.+'
        compile 'com.android.support:support-v4:21.0.0'
    } 
    

    This is noted by Google's documents here: https://developer.android.com/training/material/compatibility.html

    See dependencies section.

    Also, you can download google's sample of RecyclerView to digging out.

    Hope this will help!

提交回复
热议问题