无法解决错误膨胀类android.support.v7.widget.RecyclerView

时间:2015-06-28 20:48:41

标签: android android-recyclerview

由于

,我的应用程序崩溃了
  

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

我花了差不多3个晚上才找到解决问题的办法,但没有运气。我真的知道为什么会出现这个问题。 我正在使用android studio v 1.2.2和支持库v22 我的xml布局如下:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_story"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity$PlaceholderFragment">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/list_view_story"
            android:background="?attr/colorFragmentBackground"
            android:overScrollMode="never"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </android.support.v4.widget.SwipeRefreshLayout>

  </RelativeLayout>

我的片段:

public class StoryListFragment extends Fragment implements MVPStoryListView {

    private static final int SCROLL_THRESHOLD = 5;

    @InjectView(R.id.list_view_story)
    RecyclerView listViewStoryMain;
    @InjectView(R.id.swipe_refresh_story)
    SwipeRefreshLayout swipeRefreshLayoutMain;
    private StoryAdapter storyAdapterMain;
    private Toolbar toolbar;
    private StoryListPresenter storyListPresenter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_story, container, false);
        ButterKnife.inject(this, rootView);
        storyListPresenter = new StoryListPresenterImpl(this);
        bindSwipeRefreshView();
        bindMainListView();
        bindAdapter();      
        return rootView;
    }

我的项目根gradle是:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    ext {
        androidCompileSdkVersion = 22
        androidBuildToolsVersion = "22.0.1"

        androidApplicationId = 'com.faiz.news'
        androidMinSdkVersion = 14
        androidTargetSdkVersion = 22
        androidVersionCode = 1
        androidVersionName = "1.0"
    }
    repositories {
        jcenter()
    }
}

我的应用程序gradle:

apply plugin: 'com.android.application'

android {
    def globalConfiguration = rootProject.extensions.getByName("ext")

    compileSdkVersion globalConfiguration.getAt("androidCompileSdkVersion")
    buildToolsVersion globalConfiguration.getAt("androidBuildToolsVersion")

    defaultConfig {
        applicationId globalConfiguration.getAt("androidApplicationId")
        minSdkVersion globalConfiguration.getAt("androidMinSdkVersion")
        targetSdkVersion globalConfiguration.getAt("androidTargetSdkVersion")
        versionCode globalConfiguration.getAt("androidVersionCode")
        versionName globalConfiguration.getAt("androidVersionName")
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':domain')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:support-v13:22.2.0'
    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:palette-v7:22.2.0'
    compile 'com.tsengvn:Typekit:1.0.0'
    compile 'com.drivemode:TypefaceHelper:1.0.0@aar'
    compile 'com.koushikdutta.ion:ion:2.0.5'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.jakewharton.timber:timber:3.1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.satyan:sugar:1.3'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
}

logcat输出:

06-28 23:27:59.096  15167-15167/com.faiz.news E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.faiz.news/com.faiz.news.ui.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.widget.RecyclerView
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5455)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.widget.RecyclerView
            at android.view.LayoutInflater.createView(LayoutInflater.java:626)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at com.faiz.news.ui.fragments.StoryListFragment.onCreateView(StoryListFragment.java:46)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1188)
            at android.app.Activity.performStart(Activity.java:5382)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2276)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5455)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
            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:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:600)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at com.faiz.news.ui.fragments.StoryListFragment.onCreateView(StoryListFragment.java:46)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1188)
            at android.app.Activity.performStart(Activity.java:5382)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2276)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5455)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010006 a=-1}
            at android.content.res.Resources.loadDrawable(Resources.java:2946)
            at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
            at android.view.View.<init>(View.java:3577)
            at android.view.ViewGroup.<init>(ViewGroup.java:475)
            at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:408)
            at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:404)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:600)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at com.faiz.news.ui.fragments.StoryListFragment.onCreateView(StoryListFragment.java:46)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1188)
            at android.app.Activity.performStart(Activity.java:5382)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2276)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
            at android.app.ActivityThread.access$700(ActivityThread.java:165)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5455)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
            at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

这个问题似乎与recyclerview的背景有关。尝试删除它。