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
A related note: if you're using the support libraries, you're pretty sure your dependencies are correct, and you got here via a search for "Error inflating class CardView," then make sure your XML layout is using <android.support.v7.widget.CardView> and not just <CardView>!
The two errors are pretty similar and it took me a few minutes to facepalm when I realized that I wasn't paying attention to the full class name in the error message and I was using the non-support <CardView> in my layout without realizing it.
I got error gone by Adding Dependencies
The RecyclerView and CardView widgets are part of the v7 Support Libraries. To use these widgets in your project, add these Gradle dependencies to your app's module:
dependencies { ... compile 'com.android.support:cardview-v7:21.0.+' compile 'com.android.support:recyclerview-v7:21.0.+' }
http://developer.android.com/training/material/lists-cards.html
I solved my problem by restarting the eclipse. Also make sure you have added the jars in build path and marked it for import/export.
if you are using intellij use these steps, this actually works
These steps work for me :)
Go to File -> Import -> Existing Android code into workspace --> Browse (Go to sdk/extras/android/support/v7/cardview) --> Click ok --> Click Finish
Your project explorer will now show cardview as a project.
Right click on cardview project --> Properties --> Android(Left Pane) --> Enable isLibrary (tick the checkbox) --> Apply --> ok
Now Right click on your project --> Properties --> Android(Left pane) --> Add (under library) --> cardview --> apply --> ok
Now right click on your project again --> build path --> configure build path --> Under projects tab, add cardview
one more step you should require to remove error, that is order of cardview lib.
so right click on you project again --> properties --> Android(left pane)--> select cardview lib in library window --> and move to up
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!