报错:Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView

原文链接:http://blog.csdn.net/u010351494/article/details/47022601

最近学习RecyclerView,使用eclipse引用RecyclerView,编写完demo后编译没有问题,一运行就挂掉,错误如下:

  1. 07-22 23:05:34.553: D/AndroidRuntime(2968): Shutting down VM 
  2. 07-22 23:05:34.560: E/AndroidRuntime(2968): FATAL EXCEPTION: main  
  3. 07-22 23:05:34.560: E/AndroidRuntime(2968): Process: com.zh.myrecyclerview, PID: 2968  
  4. 07-22 23:05:34.560: E/AndroidRuntime(2968): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zh.myrecyclerview/com.zh.myrecyclerview  
  5. .MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView  
  6. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)  
  7. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)  
  8. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread.access$800(ActivityThread.java:144)  
  9. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)  
  10. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.os.Handler.dispatchMessage(Handler.java:102)  
  11. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.os.Looper.loop(Looper.java:135)  
  12. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread.main(ActivityThread.java:5221)  
  13. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.reflect.Method.invoke(Native Method)  
  14. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.reflect.Method.invoke(Method.java:372)  
  15. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)  
  16. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)  
  17. 07-22 23:05:34.560: E/AndroidRuntime(2968): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView  
  18. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.createView(LayoutInflater.java:633)  
  19. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)  
  20. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)  
  21. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)  
  22. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)  
  23. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)  
  24. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)  
  25. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.Activity.setContentView(Activity.java:2144)  
  26. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at com.zh.myrecyclerview.MainActivity.onCreate(MainActivity.java:20)  
  27. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.Activity.performCreate(Activity.java:5933)  
  28. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)  
  29. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)  
  30. 07-22 23:05:34.560: E/AndroidRuntime(2968):     ... 10 more  
  31. 07-22 23:05:34.560: E/AndroidRuntime(2968): Caused by: java.lang.reflect.InvocationTargetException  
  32. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.reflect.Constructor.newInstance(Native Method)  
  33. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.reflect.Constructor.newInstance(Constructor.java:288)  
  34. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.createView(LayoutInflater.java:607)  
  35. 07-22 23:05:34.560: E/AndroidRuntime(2968):     ... 21 more  
  36. 07-22 23:05:34.560: E/AndroidRuntime(2968): Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/recyclerview/R$styleable;  
  37. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:434)  
  38. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:404)  
  39. 07-22 23:05:34.560: E/AndroidRuntime(2968):     ... 24 more  
  40. 07-22 23:05:34.560: E/AndroidRuntime(2968): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.recyclerview.R$styleable" on path: DexPathList[[zip file "/data/app/com.zh.myrecyclerview-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]  
  41. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)  
  42. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)  
  43. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)  
  44. 07-22 23:05:34.560: E/AndroidRuntime(2968):     ... 26 more  
  45. 07-22 23:05:34.560: E/AndroidRuntime(2968):     Suppressed: java.lang.ClassNotFoundException: android.support.v7.recyclerview.R$styleable  
  46. 07-22 23:05:34.560: E/AndroidRuntime(2968):         at java.lang.Class.classForName(Native Method)  
  47. 07-22 23:05:34.560: E/AndroidRuntime(2968):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)  
  48. 07-22 23:05:34.560: E/AndroidRuntime(2968):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)  
  49. 07-22 23:05:34.560: E/AndroidRuntime(2968):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)  
  50. 07-22 23:05:34.560: E/AndroidRuntime(2968):         ... 27 more  
  51. 07-22 23:05:34.560: E/AndroidRuntime(2968):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available  
  52. 07-22 23:05:37.406: I/Process(2968): Sending signal. PID: 2968 SIG: 9  


试了很多方法都不行,整了半天,终于搞定,原来在eclipse中使用RecyclerView只能导入API21.0.0中的包才可以使用。

解决办法:进入sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0目录,找到recyclerview-v7-21.0.0.aar这个文件。用解压软件解压此文件里面有classes.jar,把这个jar包放到项目中的libs文件下即可。这个jar包就是RecyclerView要使用的,可以给它改个名字例如android-support-v7-recyclerview.jar , 便于查看。

最近升级了SDK发现sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0这个目录找不到了,所以把之前的jar包传到了csdn的服务器上,需要的可以到这下载: http://download.csdn.net/detail/u010351494/9232327

原文链接:http://blog.csdn.net/u010351494/article/details/47022601

最近学习RecyclerView,使用eclipse引用RecyclerView,编写完demo后编译没有问题,一运行就挂掉,错误如下:

  1. 07-22 23:05:34.553: D/AndroidRuntime(2968): Shutting down VM 
  2. 07-22 23:05:34.560: E/AndroidRuntime(2968): FATAL EXCEPTION: main  
  3. 07-22 23:05:34.560: E/AndroidRuntime(2968): Process: com.zh.myrecyclerview, PID: 2968  
  4. 07-22 23:05:34.560: E/AndroidRuntime(2968): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zh.myrecyclerview/com.zh.myrecyclerview  
  5. .MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView  
  6. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)  
  7. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)  
  8. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread.access$800(ActivityThread.java:144)  
  9. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)  
  10. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.os.Handler.dispatchMessage(Handler.java:102)  
  11. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.os.Looper.loop(Looper.java:135)  
  12. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread.main(ActivityThread.java:5221)  
  13. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.reflect.Method.invoke(Native Method)  
  14. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.reflect.Method.invoke(Method.java:372)  
  15. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)  
  16. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)  
  17. 07-22 23:05:34.560: E/AndroidRuntime(2968): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView  
  18. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.createView(LayoutInflater.java:633)  
  19. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)  
  20. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)  
  21. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)  
  22. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)  
  23. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)  
  24. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)  
  25. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.Activity.setContentView(Activity.java:2144)  
  26. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at com.zh.myrecyclerview.MainActivity.onCreate(MainActivity.java:20)  
  27. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.Activity.performCreate(Activity.java:5933)  
  28. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)  
  29. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)  
  30. 07-22 23:05:34.560: E/AndroidRuntime(2968):     ... 10 more  
  31. 07-22 23:05:34.560: E/AndroidRuntime(2968): Caused by: java.lang.reflect.InvocationTargetException  
  32. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.reflect.Constructor.newInstance(Native Method)  
  33. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.reflect.Constructor.newInstance(Constructor.java:288)  
  34. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.view.LayoutInflater.createView(LayoutInflater.java:607)  
  35. 07-22 23:05:34.560: E/AndroidRuntime(2968):     ... 21 more  
  36. 07-22 23:05:34.560: E/AndroidRuntime(2968): Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/recyclerview/R$styleable;  
  37. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:434)  
  38. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:404)  
  39. 07-22 23:05:34.560: E/AndroidRuntime(2968):     ... 24 more  
  40. 07-22 23:05:34.560: E/AndroidRuntime(2968): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.recyclerview.R$styleable" on path: DexPathList[[zip file "/data/app/com.zh.myrecyclerview-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]  
  41. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)  
  42. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)  
  43. 07-22 23:05:34.560: E/AndroidRuntime(2968):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)  
  44. 07-22 23:05:34.560: E/AndroidRuntime(2968):     ... 26 more  
  45. 07-22 23:05:34.560: E/AndroidRuntime(2968):     Suppressed: java.lang.ClassNotFoundException: android.support.v7.recyclerview.R$styleable  
  46. 07-22 23:05:34.560: E/AndroidRuntime(2968):         at java.lang.Class.classForName(Native Method)  
  47. 07-22 23:05:34.560: E/AndroidRuntime(2968):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)  
  48. 07-22 23:05:34.560: E/AndroidRuntime(2968):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)  
  49. 07-22 23:05:34.560: E/AndroidRuntime(2968):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)  
  50. 07-22 23:05:34.560: E/AndroidRuntime(2968):         ... 27 more  
  51. 07-22 23:05:34.560: E/AndroidRuntime(2968):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available  
  52. 07-22 23:05:37.406: I/Process(2968): Sending signal. PID: 2968 SIG: 9  


试了很多方法都不行,整了半天,终于搞定,原来在eclipse中使用RecyclerView只能导入API21.0.0中的包才可以使用。

解决办法:进入sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0目录,找到recyclerview-v7-21.0.0.aar这个文件。用解压软件解压此文件里面有classes.jar,把这个jar包放到项目中的libs文件下即可。这个jar包就是RecyclerView要使用的,可以给它改个名字例如android-support-v7-recyclerview.jar , 便于查看。

最近升级了SDK发现sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0这个目录找不到了,所以把之前的jar包传到了csdn的服务器上,需要的可以到这下载: http://download.csdn.net/detail/u010351494/9232327

猜你喜欢

转载自blog.csdn.net/skfmq/article/details/50424321