原文链接:http://www.jb51.cc/article/p-glytmdsh-bdc.html
最近学习RecyclerView,使用eclipse引用RecyclerView,编写完demo后编译没有问题,一运行就挂掉,错误如下:
- 07-2223:05:34.553:D/AndroidRuntime(2968):ShuttingdownVM
- 07-2223:05:34.560:E/AndroidRuntime(2968):FATALEXCEPTION:main
- 07-2223:05:34.560:E/AndroidRuntime(2968):Process:com.zh.myrecyclerview,PID:2968
- 07-2223:05:34.560:E/AndroidRuntime(2968):java.lang.RuntimeException:UnabletostartactivityComponentInfo{com.zh.myrecyclerview/com.zh.myrecyclerview
- .MainActivity}:android.view.InflateException:BinaryXMLfileline#7:Errorinflatingclassandroid.support.v7.widget.RecyclerView
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.app.ActivityThread.access$800(ActivityThread.java:144)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.os.Handler.dispatchMessage(Handler.java:102)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.os.Looper.loop(Looper.java:135)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.app.ActivityThread.main(ActivityThread.java:5221)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atjava.lang.reflect.Method.invoke(NativeMethod)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atjava.lang.reflect.Method.invoke(Method.java:372)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
- 07-2223:05:34.560:E/AndroidRuntime(2968):Causedby:android.view.InflateException:BinaryXMLfileline#7:Errorinflatingclassandroid.support.v7.widget.RecyclerView
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.view.LayoutInflater.createView(LayoutInflater.java:633)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.view.LayoutInflater.rInflate(LayoutInflater.java:806)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.view.LayoutInflater.inflate(LayoutInflater.java:504)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.view.LayoutInflater.inflate(LayoutInflater.java:414)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.view.LayoutInflater.inflate(LayoutInflater.java:365)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atcom.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.app.Activity.setContentView(Activity.java:2144)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atcom.zh.myrecyclerview.MainActivity.onCreate(MainActivity.java:20)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.app.Activity.performCreate(Activity.java:5933)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
- 07-2223:05:34.560:E/AndroidRuntime(2968):...10more
- 07-2223:05:34.560:E/AndroidRuntime(2968):Causedby:java.lang.reflect.InvocationTargetException
- 07-2223:05:34.560:E/AndroidRuntime(2968):atjava.lang.reflect.Constructor.newInstance(NativeMethod)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atjava.lang.reflect.Constructor.newInstance(Constructor.java:288)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.view.LayoutInflater.createView(LayoutInflater.java:607)
- 07-2223:05:34.560:E/AndroidRuntime(2968):...21more
- 07-2223:05:34.560:E/AndroidRuntime(2968):Causedby:java.lang.NoClassDefFoundError:Failedresolutionof:Landroid/support/v7/recyclerview/R$styleable;
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.support.v7.widget.RecyclerView.<init>(RecyclerView.java:434)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atandroid.support.v7.widget.RecyclerView.<init>(RecyclerView.java:404)
- 07-2223:05:34.560:E/AndroidRuntime(2968):...24more
- 07-2223:05:34.560:E/AndroidRuntime(2968):Causedby:java.lang.ClassNotFoundException:Didn'tfindclass"android.support.v7.recyclerview.R$styleable"onpath:DexPathList[[zipfile"/data/app/com.zh.myrecyclerview-1/base.apk"],nativeLibraryDirectories=[/vendor/lib,/system/lib]]
- 07-2223:05:34.560:E/AndroidRuntime(2968):atdalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atjava.lang.ClassLoader.loadClass(ClassLoader.java:511)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atjava.lang.ClassLoader.loadClass(ClassLoader.java:469)
- 07-2223:05:34.560:E/AndroidRuntime(2968):...26more
- 07-2223:05:34.560:E/AndroidRuntime(2968):Suppressed:java.lang.ClassNotFoundException:android.support.v7.recyclerview.R$styleable
- 07-2223:05:34.560:E/AndroidRuntime(2968):atjava.lang.Class.classForName(NativeMethod)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atjava.lang.BootClassLoader.findClass(ClassLoader.java:781)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atjava.lang.BootClassLoader.loadClass(ClassLoader.java:841)
- 07-2223:05:34.560:E/AndroidRuntime(2968):atjava.lang.ClassLoader.loadClass(ClassLoader.java:504)
- 07-2223:05:34.560:E/AndroidRuntime(2968):...27more
- 07-2223:05:34.560:E/AndroidRuntime(2968):Causedby:java.lang.NoClassDefFoundError:Classnotfoundusingthebootclassloader;nostackavailable
- 07-2223:05:37.406:I/Process(2968):Sendingsignal.PID:2968SIG: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