Eclipse出现Caused by: java.lang.NoClassDefFoundError: android.support.v7.recyclerview.R$styleable

在eclipse中使用RecyclerView,编译没有问题,但是运行时候会出现如下错误,百思不得其解,又说v4包与v7包版本不一致,有说没有导入v7-compat包的,经反复实验,得出结论跟v4包、v7compat包都没有关系,跟recyclerview的版本有关系,eclipse只能导入21.0.0的才可以使用。

07-12 10:38:24.331: E/AndroidRuntime(16862): FATAL EXCEPTION: main
07-12 10:38:24.331: E/AndroidRuntime(16862): Process: com.example.recyclerdemo, PID: 16862
07-12 10:38:24.331: E/AndroidRuntime(16862): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.recyclerdemo/com.example.recyclerdemo.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class android.support.v7.widget.RecyclerView
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2224)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.app.ActivityThread.access$800(ActivityThread.java:144)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.os.Handler.dispatchMessage(Handler.java:102)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.os.Looper.loop(Looper.java:136)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.app.ActivityThread.main(ActivityThread.java:5153)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at java.lang.reflect.Method.invokeNative(Native Method)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at java.lang.reflect.Method.invoke(Method.java:515)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at dalvik.system.NativeStart.main(Native Method)
07-12 10:38:24.331: E/AndroidRuntime(16862): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class android.support.v7.widget.RecyclerView
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.view.LayoutInflater.createView(LayoutInflater.java:621)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.app.Activity.setContentView(Activity.java:1965)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at com.example.recyclerdemo.MainActivity.onCreate(MainActivity.java:19)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.app.Activity.performCreate(Activity.java:5356)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
07-12 10:38:24.331: E/AndroidRuntime(16862):    ... 11 more
07-12 10:38:24.331: E/AndroidRuntime(16862): Caused by: java.lang.reflect.InvocationTargetException
07-12 10:38:24.331: E/AndroidRuntime(16862):    at java.lang.reflect.Constructor.constructNative(Native Method)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.view.LayoutInflater.createView(LayoutInflater.java:595)
07-12 10:38:24.331: E/AndroidRuntime(16862):    ... 22 more
07-12 10:38:24.331: E/AndroidRuntime(16862): Caused by: java.lang.NoClassDefFoundError: android.support.v7.recyclerview.R$styleable
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:434)
07-12 10:38:24.331: E/AndroidRuntime(16862):    at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:404)
07-12 10:38:24.331: E/AndroidRuntime(16862):    ... 25 more

正确:
在android-sdk/extras/android/m2repository/com/android/support/recyclerview-v7目录下根据版本号21.0.0目录可以找到一个名为recyclerview-v7-21.0.0.aar的文件。解压此文件里面有classes.jar,引用此jar包。
错误
在android-sdk/extras/android/support/v7/recyclerview目录下面有libs,里面有jar包,引用此jar包。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值