回收视图 - android.view.InflateException

RecycleView - android.view.InflateException

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

我已经检查了我所有的 Java 和 XML 代码,没有错误。我已经多次导入 android-support-v7-recyclerview,多次尝试 Project > Clean,重新启动 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.Whosebug.question, PID: 2795
01-21 13:31:45.522: E/AndroidRuntime(2795): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Whosebug.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.access0(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.Whosebug.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

中针对此问题重命名了包名

依赖性管理可能会加重。

使用 Android Studio,您会声明对 appcompat-v7 的依赖,而 Gradle 对于 Android 会找到兼容的 support-v4 并使用它。大多数时候,这就是所需的全部内容。

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

之类的东西