膨胀类 android.support.v7.widget.RecyclerView(Eclipse) 时出错
Posted
技术标签:
【中文标题】膨胀类 android.support.v7.widget.RecyclerView(Eclipse) 时出错【英文标题】:Error inflating class android.support.v7.widget.RecyclerView(Eclipse) 【发布时间】:2017-02-01 00:47:03 【问题描述】:我想在我的 Eclipse 项目中使用 android.support.v7.widget.RecyclerView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_
android:layout_
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ir.sheikhoo.sis.EditeActivity" >
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_
android:layout_>
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
但它会引发错误
09-23 11:33:37.968: E/AndroidRuntime(20310): java.lang.RuntimeException: Unable to start activity ComponentInfoir.sheikhoo.sis/ir.sheikhoo.sis.EditeActivity: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.v7.widget.RecyclerView
完整的错误日志
09-23 11:55:53.288: E/AndroidRuntime(28333): FATAL EXCEPTION: main
09-23 11:55:53.288: E/AndroidRuntime(28333): Process: ir.sheikhoo.sis, PID: 28333
09-23 11:55:53.288: E/AndroidRuntime(28333): java.lang.RuntimeException: Unable to start activity ComponentInfoir.sheikhoo.sis/ir.sheikhoo.sis.EditeActivity: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.v7.widget.RecyclerView
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread.access$800(ActivityThread.java:166)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.os.Handler.dispatchMessage(Handler.java:102)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.os.Looper.loop(Looper.java:136)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread.main(ActivityThread.java:5590)
09-23 11:55:53.288: E/AndroidRuntime(28333): at java.lang.reflect.Method.invokeNative(Native Method)
09-23 11:55:53.288: E/AndroidRuntime(28333): at java.lang.reflect.Method.invoke(Method.java:515)
09-23 11:55:53.288: E/AndroidRuntime(28333): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
09-23 11:55:53.288: E/AndroidRuntime(28333): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
09-23 11:55:53.288: E/AndroidRuntime(28333): at dalvik.system.NativeStart.main(Native Method)
09-23 11:55:53.288: E/AndroidRuntime(28333): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.v7.widget.RecyclerView
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
09-23 11:55:53.288: E/AndroidRuntime(28333): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:331)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.Activity.setContentView(Activity.java:2018)
09-23 11:55:53.288: E/AndroidRuntime(28333): at ir.sheikhoo.sis.EditeActivity.onCreate(EditeActivity.java:13)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.Activity.performCreate(Activity.java:5447)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
09-23 11:55:53.288: E/AndroidRuntime(28333): ... 11 more
09-23 11:55:53.288: E/AndroidRuntime(28333): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.RecyclerView" on path: DexPathList[[zip file "/data/app/ir.sheikhoo.sis-22.apk"],nativeLibraryDirectories=[/data/app-lib/ir.sheikhoo.sis-22, /vendor/lib, /system/lib]]
09-23 11:55:53.288: E/AndroidRuntime(28333): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-23 11:55:53.288: E/AndroidRuntime(28333): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
09-23 11:55:53.288: E/AndroidRuntime(28333): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.createView(LayoutInflater.java:566)
09-23 11:55:53.288: E/AndroidRuntime(28333): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:703)
09-23 11:55:53.288: E/AndroidRuntime(28333): ... 21 more
我使用android.support-23.2.1
和目标sdk android:targetSdkVersion="23"
这是我的sdk
【问题讨论】:
您能发布完整的错误日志吗?或者仅此而已?该错误通常指向 Activity 中的某些异常——在本例中为EditeActivity
。
我的建议是使用带有 gradle 的 Android Studio。使用 recyclerview 之类的库更容易,并且您在开发时会获得更多乐趣;-)
@ishmaelMakitla 我添加完整的错误日志
您的 jar 位于名为 libs
的目录中,我认为您仅添加了 lib
的依赖项。请检查依赖关系。
将 xmlns:app="schemas.android.com/apk/res-auto" 添加到相对布局中。
【参考方案1】:
我认为您的 cardview jar 文件中的问题,它与其他库的版本不匹配。
1、你需要使用cardview或其他版本低于compileSdkVersion和targetSdkVersion的库。在这种情况下,您使用版本 cardview-v7-21.0.0.jar,因此您的 compileSdkVersion 和 targetSdkVersion 必须为 21.0.0 或更高版本。
第二,我认为您需要切换 Android Studio,它可以轻松管理库。
【讨论】:
我将所有库更改为 android.support-23.2.1 并使用 api 23 作为目标...我更改了我的帖子以上是关于膨胀类 android.support.v7.widget.RecyclerView(Eclipse) 时出错的主要内容,如果未能解决你的问题,请参考以下文章
膨胀类 CollapsingToolbarLayout 时出错