简体   繁体   English

无法将CardView添加到Eclipse中的布局

[英]Unable to add CardView to layout in Eclipse

I am using Eclipse and trying to add CardView to my layout. 我正在使用Eclipse并尝试将CardView添加到我的布局中。 However I keep getting an exception: 但是我一直有例外:

02-27 23:33:41.982: E/AndroidRuntime(20071): FATAL EXCEPTION: main
02-27 23:33:41.982: E/AndroidRuntime(20071): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.materialcontactpicker/com.example.materialcontactpicker.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.CardView

... most of the crap that you usually ignore ...

02-27 23:33:41.982: E/AndroidRuntime(20071): Caused by: java.lang.NoClassDefFoundError: android.support.v7.cardview.R$styleable
02-27 23:33:41.982: E/AndroidRuntime(20071):    at android.support.v7.widget.CardView.initialize(CardView.java:203)
02-27 23:33:41.982: E/AndroidRuntime(20071):    at android.support.v7.widget.CardView.<init>(CardView.java:101)
02-27 23:33:41.982: E/AndroidRuntime(20071):    ... 24 more  

I have: 我有:
1. Imported appcompat_v7 to my workspace, added it to libraries. 1.将appcompat_v7导入我的工作区,将其添加到库中。
2. Imported cardview project and added it to libraries. 2.导入的cardview项目并将其添加到库中。
3. Configured the build path and added cardview to the "Projects". 3.配置构建路径并将cardview添加到“项目”。
4. My targetSdkVersion is 21. 我的targetSdkVersion是21。

However, I still get the error. 但是,我仍然得到错误。

How do I solve this? 我该如何解决这个问题?

I faced the similar issue yesterday in eclipse. 昨天我在日食中遇到了类似的问题。 Below steps work for me. 以下步骤适合我。

  1. Remove cardView project from buildpath. 从buildpath中删除cardView项目。 Delete existing CardView project from workspace. 从工作区删除现有的CardView项目。
  2. Clean Project. 清洁项目。
  3. Restart eclipse. 重启eclipse。
  4. Import CardView project again. 再次导入CardView项目。
  5. Right click on the CardView Project. 右键单击CardView项目。 Go to Properties. 转到“属性”。 Make sure "is Library" option is checked. 确保选中“is Library”选项。
  6. Now right click on your project -> build path -> configure build path -> Under projects tab, add cardview. 现在右键单击您的项目 - >构建路径 - >配置构建路径 - >在项目选项卡下,添加cardview。

Hope it helps.. 希望能帮助到你..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM