Error when adding CardView to layout

£可爱£侵袭症+ 提交于 2019-11-29 05:57:55

This is a bug in Android Studio, see https://code.google.com/p/android/issues/detail?id=79071

One of the comments of the patch reads: "This was causing card view rendering to fail. CardView declared styles of the form CardView.Dark due to which the generated R class failed to load."

Next version should have this fixed according to the bug report (the patch is on branch studio-1.0-dev). They say to build the project once as a workaround, but this does not fix it for me (even though I have exactly the same error and stack trace).

I was able to get it to work on the emulator by changing my build.gradle to this:

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

Make sure you have the support repository installed from the SDK Manager! Hope this helps

EDIT: as someone suggested using 'com.android.support:cardview-v7:23.1' is a better practice but it not required.

try adding this line to your RelativeLayout

xmlns:card_view="http://schemas.android.com/apk/res-auto"

It solved me by adding xmlns:card_view="http://schemas.android.com/apk/res-auto"

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            xmlns:card_view="http://schemas.android.com/apk/res-auto"> --->> ******
        ....
        ...
        <android.support.v7.widget.CardView>
    ..
...
.....

        </android.support.v7.widget.CardView>
        </LinearLayout>

I was able to get this to work by adding the following to my build.gradle: compile 'com.android.support:cardview-v7:21.+'

Hope this helps.

Try adding this to your build.gradle file

dependencies {
...
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!