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

前端 未结 7 973
长情又很酷
长情又很酷 2020-12-16 23:54

I am using CardView of support library in my android app. I tried 4-5 hours to resolve this but i could not get success.

I have added CardView

相关标签:
7条回答
  • 2020-12-17 00:34

    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.

    0 讨论(0)
  • 2020-12-17 00:37

    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.

    0 讨论(0)
  • 2020-12-17 00:39

    (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.
    0 讨论(0)
  • 2020-12-17 00:43

    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

    0 讨论(0)
  • 2020-12-17 00:43

    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>
    
    0 讨论(0)
  • 2020-12-17 00:44

    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.

    0 讨论(0)
提交回复
热议问题