RecycleView - android.view.InflateException

时间:2015-01-21 13:48:51

标签: android android-recyclerview

今天我决定使用RecycleView作为我的ListView(从Android 5.0推荐)。我已经使用this tutorial开始,因为我之前从未使用过RecyclerView。

我检查了所有Java和XML代码,没有错误。我已多次导入android-support-v7-recyclerview,试过Project>多次清理,重新启动Eclipse但没有任何效果。我有appcompat_v7和android-support-v4包含在项目中,从来没有遇到任何问题。

启动我的应用程序后,应用程序崩溃并在logcat中获取

01-21 13:31:45.522: E/AndroidRuntime(2795): FATAL EXCEPTION: main
01-21 13:31:45.522: E/AndroidRuntime(2795): Process: com.stackoverflow.question, PID: 2795
01-21 13:31:45.522: E/AndroidRuntime(2795): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stackoverflow.question/activities.MainActivity}: android.view.InflateException: Binary XML file line #158: Error inflating class android.support.v7.widget.RecyclerView
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.os.Handler.dispatchMessage(Handler.java:102)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.os.Looper.loop(Looper.java:135)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.app.ActivityThread.main(ActivityThread.java:5221)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at java.lang.reflect.Method.invoke(Native Method)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at java.lang.reflect.Method.invoke(Method.java:372)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
01-21 13:31:45.522: E/AndroidRuntime(2795): Caused by: android.view.InflateException: Binary XML file line #158: Error inflating class android.support.v7.widget.RecyclerView
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.view.LayoutInflater.createView(LayoutInflater.java:633)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.app.Activity.setContentView(Activity.java:2144)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at activities.MainActivity.onCreate(MainActivity.java:55)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.app.Activity.performCreate(Activity.java:5933)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
01-21 13:31:45.522: E/AndroidRuntime(2795):     ... 10 more
01-21 13:31:45.522: E/AndroidRuntime(2795): Caused by: java.lang.reflect.InvocationTargetException
01-21 13:31:45.522: E/AndroidRuntime(2795):     at java.lang.reflect.Constructor.newInstance(Native Method)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.view.LayoutInflater.createView(LayoutInflater.java:607)
01-21 13:31:45.522: E/AndroidRuntime(2795):     ... 22 more
01-21 13:31:45.522: E/AndroidRuntime(2795): Caused by: java.lang.NoSuchMethodError: No static method create(Landroid/content/Context;Landroid/view/animation/Interpolator;)Landroid/support/v4/widget/ScrollerCompat; in class Landroid/support/v4/widget/ScrollerCompat; or its super classes (declaration of 'android.support.v4.widget.ScrollerCompat' appears in /data/app/com.stackoverflow.question-1/base.apk)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.support.v7.widget.RecyclerView$ViewFlinger.<init>(RecyclerView.java:2686)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:231)
01-21 13:31:45.522: E/AndroidRuntime(2795):     at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:266)
01-21 13:31:45.522: E/AndroidRuntime(2795):     ... 25 more

我一直在争论这个问题超过3个小时,在很多帖子中搜索没有结果。我可以通过从activity_main.xml中删除<android.support.v7.widget.RecyclerView .... />来阻止应用程序崩溃,因此我确信这是我在使用RecyclerView时出错了。

我现在可以提供任何帮助,因为我现在不知道该怎么做才能让它起作用。它可能是支持库吗?

PS:在logcat

中为此问题重新命名的包名称

1 个答案:

答案 0 :(得分:0)

依赖性管理可能会加剧。

使用Android Studio,您会声明对appcompat-v7的依赖,而Gradle for Android会找到兼容的support-v4并使用它。很多时候,这就是所需要的。

但是,使用Eclipse,您必须手动完成所有操作。如果升级依赖于另一个库(例如appcompat-v7)的库(例如,support-v4),则需要确保使用兼容对,通常通过同时升级它们。当您使用自己依赖的第三方库时,这可能会带来挑战,甚至可能出货support-v4