8

我正在測試新的API 21,我試圖創建一個RecyclerView,但我堅持依賴問題。SDK 5.0 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預覽問題。執行期間,一切正常

+0

這個錯誤發生在IDE預覽? – ben75 2014-10-19 18:01:17

+0

是的。但執行時,我得到NullPointer在我的mRecyclerView – 2014-10-19 19:59:58

+0

如果您使用_buildToolsVersion 21.0.0_或_21.0.1_有什麼幫助嗎? – harism 2014-10-19 21:37:17

回答

8

新的RecyclerView尚未在Studio中工作。 Google正在進行修復。 (Open Issue 72117

+3

現在就可以運行 - 您需要遵循google的deepanshu步驟:「如果用戶仍然想知道,您應該通過SDK Manager更新到API 22的最新SDK平臺,並更新爲通過SDK Manager更新支持存儲庫以及在您的build.gradle文件中使用最新版本(22.0.0)的最新回收視圖「 – Simon 2015-05-16 17:02:41

1

你的API和RecyclerView版本應該是相同的

同步搖籃,如:

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' 
    } 
相關問題