Android Studio CardView错误:无法实例化 [英] Android Studio CardView error: could not be instantiated
本文介绍了Android Studio CardView错误:无法实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我在activity_main.xml中放入CardView时,都会出现此错误.
I get this error whenever I put a CardView in my activity_main.xml.
无法实例化以下类:
- android.support.v7.widget.CardView
(打开类,显示异常,清除缓存)
- android.support.v7.widget.CardView
(Open Class, Show Exception, Clear Cache)
我已将其添加到build.gradle中:
I've added this to the build.gradle :
compile 'com.android.support:design:23.2.1'
//CardView
compile 'com.android.support:cardview-v7:25.0.0'
//RecyclerView
compile 'com.android.support:recyclerview-v7:25.0.0'
这是我的activity_main.xml
This is my activity_main.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="com.example.ivanp.meteostanica.TvrdjavaFragment"
android:orientation="vertical"
android:weightSum="1"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/bubanj"
android:id="@+id/imageView8"
android:adjustViewBounds="true" />
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_margin="40dp"
android:id="@+id/card_view"
android:layout_width="fill_parent"
android:layout_height="250dp"
card_view:cardCornerRadius="2dp">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView" />
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
推荐答案
万一它缺少样式,请在您的CardView中添加 style ="@ style/CardView"
.
In case its about missing styles add style="@style/CardView"
to your CardView.
这篇关于Android Studio CardView错误:无法实例化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文