SDK 5.0 RecyclerView无法实例化

时间:2014-10-19 16:26:10

标签: android android-layout android-fragments android-5.0-lollipop

我正在测试新的API 21,我尝试创建一个RecyclerView,但我遇到了依赖性问题。

错误看起来像那样

enter image description here

我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin">
    <!-- A RecyclerView with some commonly used attributes -->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/mRecyclerView"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

和我的gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.agonist.samplify"
        minSdkVersion 17
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:cardview-v7:+'
    compile 'com.android.support:recyclerview-v7:+'
}

我不知道该怎么做。我试图清理/构建项目,但它留在这里。有什么想法吗?

编辑:Finnaly它只是一个IDE预览问题。执行期间一切正常

2 个答案:

答案 0 :(得分:8)

新的RecyclerView尚未在Studio中运行。谷歌正在努力修复。 (Open Issue 72117

答案 1 :(得分:1)

您的API和RecyclerView版本应该相同

同步Gradle:

    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile 'com.android.support:recyclerview-v7:23.0.1'
    }