码迷,mamicode.com
首页 > 移动开发 > 详细

Android:加载CardView,RecyclerView异常解决方案

时间:2015-06-04 19:23:15      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

  今天下午,在自己的项目中添加了对RecyclerView的支持,但是一直报出“Caused by: java.lang.NoClassDefFound

Error: android.support.v7.recyclerview.R$styleable”的异常,在网上搜罗了一遭,稀里糊涂一下午仍没有解决问题,最后自己尝试从最初加载类库入手找问题,结果最终找到的原因都让自己萌生了想把自己杀了的念头。

  下面从头一一说起:

  首先,建议大家在使用Google的Android Support Library时,不要采用直接将..\sdk\extras\android\m2repository

\com\android\support\recyclerview-v7中的xx.aar文件复制到libs目录,添加Build Path这种方式,还是导入Android 代码最官方;不知道如何导入的笔者参见Google官方链接:http://developer.android.com/tools/support-library/setup.html#libs-with-res。

  其次,对于加载CardView,RecyclerView时报出的异常一种是android-support-v4.jar这个包版本不匹配,另一种就是在导完Android Support Library后,点击鼠标右键——Properties——Android——勾选Is Library——点击Apply。记住一定要点击Apply,应用当前改变,否则配置失效。我就是在导完RecyclerView包后,没点击Apply,结果一直报出上述红色标注的异常,困扰了我一下午。

  最后将完整的导包实践罗列一下,方便大家查阅。  

    • Select File > Import.
    • Select Existing Android Code Into Workspace and click Next.
    • Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding theappcompat project, browse to <sdk>/extras/android/support/v7/appcompat/.
    • Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
    • In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both theandroid-support-v4.jar and android-support-v7-appcompat.jar files.
    • Right-click the library project folder and select Properties > check Is Library>click Apply.
    • Click OK to complete the changes.

 

Android:加载CardView,RecyclerView异常解决方案

标签:

原文地址:http://www.cnblogs.com/warnier-zhang/p/4552610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!