【发布时间】:2016-05-25 12:37:01
【问题描述】:
我尝试在我的应用中使用 RecyclerView。 我有以下问题:
"以下类无法实例化: android.support.v7.widget.recyclerview 提示:使用 View.IsInEditMode()"
我在这个论坛上阅读了很多文章,这些文章帮助了很多用户,但对我来说,这些方法在我的程序中不起作用。
我将我的 Android Studio 更新到了最新版本:Beta 4 (Canary) 和 Sdk 版本,但我不确定我的 build.grade 是否正确更新。
我认为这可能是由于此 Android Studio 的某些不稳定版本引起的,但我不确定。很多人通过更新软件解决了这个问题。
当我在 API23 上设置时,它编译但在我的 API 21 (Lollipop) 上不起作用。
有人可以帮我解决这个问题吗?
我的build.grade:
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.karol.material_test"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
}
布局:
<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:background="#3D5AFE"
tools:context="com.example.karol.material_test.NavigationDrawerFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:id="@+id/containerDrawerImage"
android:layout_width="match_parent"
android:background="#BBDEFB"
android:layout_height="wrap_content">
<ImageView
android:layout_marginTop="@dimen/margin_top"
android:layout_width="140dp"
android:layout_height="140dp"
android:src="@drawable/karol"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
错误:
【问题讨论】:
-
请显示完整的错误消息,并附上您看到的上下文。还要显示您添加回收站视图的布局。
-
@DougStevenson,我添加了这个布局和错误。你在我的代码中看到了什么错误吗?
-
@war_Hero 我已经做过很多次了,但它并没有改善我的程序。
-
尝试删除现有的导入,然后再做一次
-
@war_Hero 是什么意思?我应该删除此布局或项目吗?对不起,我不明白你的说法。
标签: java android android-studio android-recyclerview