9

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 as a library in my project & v7 appcompat also

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="5dp"
    android:orientation="horizontal"
    app:cardCornerRadius="4dp" >

But my app is crashing with below logs

10-31 18:41:39.577: E/AndroidRuntime(5666): FATAL EXCEPTION: main
10-31 18:41:39.577: E/AndroidRuntime(5666): Process: com.xyzladdoo, PID: 5666
10-31 18:41:39.577: E/AndroidRuntime(5666): android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v7.widget.CardView
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at com.xyzladdoo.adapters.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:85)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at com.xyzladdoo.adapters.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:1)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:2915)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:2511)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v7.widget.LinearLayoutManager$RenderState.next(LinearLayoutManager.java:1425)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:999)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:524)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:1461)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:1600)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:543)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1594)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:887)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:502)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.View.layout(View.java:14860)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewGroup.layout(ViewGroup.java:4643)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2013)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1770)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1019)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5725)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at android.view.Choreographer.doFrame(Choreographer.java:544)
10-31 18:41:39.577: E/AndroidRuntime(5666):     at an

Any help ? Thanks in advance.

11
  • Check out this link please : stackoverflow.com/questions/24449344/… Commented Oct 31, 2014 at 13:24
  • is that your xml?, post more of it, and also your inflate. Commented Oct 31, 2014 at 13:25
  • @FaroukTouzi i am using adt Commented Oct 31, 2014 at 13:27
  • add xmlns:card_view="schemas.android.com/apk/res-auto" line Commented Oct 31, 2014 at 13:45
  • 1
    I fixed my issue. I had set a drawable set as my android:foreground="@drawable/ripple.xml" which uses the API 21 ripple selector Commented Nov 20, 2014 at 10:11

7 Answers 7

7

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

Sign up to request clarification or add additional context in comments.

4 Comments

You are wellcome. I met this error before. I Googled and find two questions on StackOverFlow about this issue, but one of them have answer that help me resolve the issue. So i copy/paste to here :)
Actually I added v7 abcompat library to my project and thought that is enough to bring cardview too. Later I realised by your answer that cardView lib is available separately. Thanks a lot..
Don't forget to add the actual files in the "libs" folder to the buildpath and then check it in Order and Export. This is a must according to developer.android.com/tools/support-library/…
Very useful comment, I spent more than half day handling this error (but with recyclerview in eclipse) and finally I find right answer! Thank you, bro!
2

(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.

Comments

1

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.

Comments

1

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.

1 Comment

But now, I recommend you to use android studio
0

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

Comments

0

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>

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.