Exception : android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v7.widget.CardView

。_饼干妹妹 提交于 2019-11-29 04:17:20
Justin

Let import cardview as a library:
Go to File -> Import -> Existing Android code into workspace --> Browse (Go to sdk/extras/android/support/v7/cardview) --> Click ok --> Click Finish

Your project explorer will now show cardview as a project.

Right click on cardview project --> Properties --> Android(Left Pane) --> Enable isLibrary (tick the checkbox) --> Apply --> ok

Now Right click on your project --> Properties --> Android(Left pane) --> Add (under library) --> cardview --> apply --> ok

Now right click on your project again --> build path --> configure build path --> Under projects tab, add cardview

You are done.
Source

(for intellij users)

  • click in your project,
  • right click -> open Module Settings
  • import cardview from \sdk\extras\android\support\v7\
  • add .jar file to cardview module
  • click on your project and give module dependency to cardview
  • now, click (+) button on cardview -> android -> at top you will see a check box (library module), enable it.
  • click ok and close your settings dialog.
  • rebuild your project and run it.

Support libs that contain resources other than compiled classes (like XMLs) cannot be added as just jars.

Please follow the steps described by this:

https://developer.android.com/tools/support-library/setup.html#libs-with-res

Let us now if that works.

To fix this problem . first you must add cardview from the \sdk\extras\android\support

  1. Close the main project.
  2. Remove the android-support-v7-appcompat .
  3. Restart the Eclipse.
  4. Add the android-support-v7-appcompat .
  5. Clean,To build the project.
  6. Then open the main project and build all the projects.
  7. The error still remains. Restart eclipse. That's it.

That works for me.

Try this..

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_gravity="center"
    android:layout_width="200dp"
    android:layout_height="200dp"
    card_view:cardCornerRadius="4dp">


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

Reference : Create Cards

Try using like this with the outer linearlayout.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    ... >
    <!-- A CardView that contains a TextView -->
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        card_view:cardCornerRadius="4dp">

        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v7.widget.CardView>
</LinearLayout>

I had the same problem as you.

In Eclipse, when you import cardview from directory \sdk\extras\android\support\v7\cardview follow the steps that are commented in "Adding libraries with resources -> Eclipse" in the official documentation: https://developer.android.com/intl/es/tools/support-library/setup.html#libs-with-res

Before adding cardview as library to your project, go to "Properties -> Android" of cardview project and add the android-support-v7-appcompat library. Don't forget check "IsLibrary".

Now, you can add cardview as library to your project. Clean both projects to refresh the changes.

I hope it helps you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!