错误膨胀类android.support.v7.widget.RecyclerView

我试图在我现有的项目中使用RecyclerView,生成没有错误,但没有发现类RecyclerView的错误,同时充气。 看不到我做错了什么。 感谢您的帮助!

//activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> //MainActivity.onCreate @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView) findViewById(R.id.recyclerView); ItemData itemsData[] = { new ItemData("Help",R.drawable.visa), new ItemData("Delete",R.drawable.sample), new ItemData("Cloud",R.drawable.sample), new ItemData("Favorite",R.drawable.sample), new ItemData("Like",R.drawable.sample), new ItemData("Rating",R.drawable.sample)}; // 2. set layoutManger recyclerView.setLayoutManager(new LinearLayoutManager(this)); // 3. create an adapter MyAdapter mAdapter = new MyAdapter(itemsData); // 4. set adapter recyclerView.setAdapter(mAdapter); // 5. set item animator to DefaultAnimator //recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setHasFixedSize(true); } 

//build.gradle

 apply plugin: 'com.android.application' android { compileSdkVersion 20 buildToolsVersion '19.1.0' defaultConfig { applicationId "com.domain.project" minSdkVersion 19 targetSdkVersion 20 versionCode 1 versionName "1.0" } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:support-v4:+' compile 'com.android.support:support-v13:+' compile project(':facebook-3.15') compile project(':parse-1.5.1') compile project(':viewpagerindicator-2.4.1') compile 'com.github.manuelpeinado.fadingactionbar:fadingactionbar:3.1.2' compile 'com.android.support:cardview-v7:+' compile 'com.android.support:recyclerview-v7:+' compile 'com.google.android.gms:play-services:+' } configurations { // to avoid double inclusion of support libraries all*.exclude group: 'com.android.support', module: 'support-v4' } 

// logcat的

 08-24 17:49:27.626 27544-27544/com.domain.project E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.domain.project, PID: 27544 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.domain.project/com.domain.project.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5139) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView at android.view.LayoutInflater.createView(LayoutInflater.java:620) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at android.view.LayoutInflater.inflate(LayoutInflater.java:353) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343) at android.app.Activity.setContentView(Activity.java:1929) at com.domain.project.MainActivity.onCreate(MainActivity.java:35) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)            at android.app.ActivityThread.access$800(ActivityThread.java:144)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:136)            at android.app.ActivityThread.main(ActivityThread.java:5139)            at java.lang.reflect.Method.invokeNative(Native Method)            at java.lang.reflect.Method.invoke(Method.java:515)            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)            at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at android.view.LayoutInflater.createView(LayoutInflater.java:594)            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)            at android.app.Activity.setContentView(Activity.java:1929)            at com.domain.project.MainActivity.onCreate(MainActivity.java:35)            at android.app.Activity.performCreate(Activity.java:5231)            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)            at android.app.ActivityThread.access$800(ActivityThread.java:144)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:136)            at android.app.ActivityThread.main(ActivityThread.java:5139)            at java.lang.reflect.Method.invokeNative(Native Method)            at java.lang.reflect.Method.invoke(Method.java:515)            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)            at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NoClassDefFoundError: android.support.v4.util.Pools$SimplePool at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:121) at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:213)            at java.lang.reflect.Constructor.constructNative(Native Method)            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)            at android.view.LayoutInflater.createView(LayoutInflater.java:594)            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)            at android.app.Activity.setContentView(Activity.java:1929)            at com.domain.project.MainActivity.onCreate(MainActivity.java:35)            at android.app.Activity.performCreate(Activity.java:5231)            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)            at android.app.ActivityThread.access$800(ActivityThread.java:144)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:136)            at android.app.ActivityThread.main(ActivityThread.java:5139)            at java.lang.reflect.Method.invokeNative(Native Method)            at java.lang.reflect.Method.invoke(Method.java:515)            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)            at dalvik.system.NativeStart.main(Native Method) 

Solutions Collecting From Web of "错误膨胀类android.support.v7.widget.RecyclerView"

请检查你的支持库是否更新到最新..

com.android.support:support-v4:和com.android.support:recyclerview-v7

我的问题是,该库是使用JDK1.6而不是1.7编译的。

这里find解决scheme的链接

在gradle文件中添加依赖关系。

 dependencies{ compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.android.support:recyclerview-v7:23.3.0' } 

我想到了。 在build.gradle中删除以下configuration将使recyclerview工作。 这导致我另一个问题: android studio:gradle依赖关系错误

 configurations { // to avoid double inclusion of support libraries all*.exclude group: 'com.android.support', module: 'support-v4' } 

只需将以下内容添加到您的proguard-rules.pro中,

 -keep public class android.support.v7.widget.** { *; } 

在互联网上试了一切之后,我通过观察小错误来解决回收站的膨胀错误。 首先,您是否检查了libs文件夹中的android-support-v7-recyclerview.jar库? 如果是,那么检查你的目标sdk版本的清单文件是否为21

 <uses-sdk android:minSdkVersion="11" //or whatever you need android:targetSdkVersion="21" /> 

也许这可以帮助未来的某个人,而不是像我一样浪费天。

看看我的答案在这里错误膨胀类RecyclerView 。 简而言之, 在尝试将RecyclerView添加到XML 之前 ,您需要导入recyclerview和appcompat依赖项并进行同步。

—从Android网站引用。

依赖

要在早于5.0(API级别21)的Android版本中使用这些function,请将Android v7支持库作为Gradle依赖项包含在您的项目中:

 dependencies { compile 'com.android.support:appcompat-v7:21.0.+' compile 'com.android.support:cardview-v7:21.0.+' compile 'com.android.support:recyclerview-v7:21.0.+' } 

为了让它在Eclipse下工作,我在工作区中添加了RecyclerView作为库。 然后在ANDROID LIBRARY下添加到我的项目中。 最后。 失去了三个小时。

我有类似的错误信息,并尝试了许多build议的步骤从这个网站的答案。

java.lang.RuntimeException:无法启动活动ComponentInfo {com.abc.def / com.abc.def.MainActivity}:android.view.InflateException:二进制XML文件行#8:

最后意识到由于某些原因,我的布局中的标签是:

 android.support.v7.internal.widget.RecyclerView 

代替

 android.support.v7.widget.RecyclerView. 

我不确定v7和widget之间是如何“内部”的,但是一旦我移除了,错误就消失了。 不要说其他人会犯同样的错误,只是为了让人们知道你的布局xml中的某个地方有个错误可能是这个错误信息的原因。

我也有同样的例外。

简单的解决scheme是将layout_behaviour添加到回收站视图:

 app:layout_behavior="@string/appbar_scrolling_view_behavior"