0

I am getting error on inflating CardView.

Inside adapter's getView():

...
    LinearLayout layoutView = (LinearLayout) 
inflater.inflate(R.layout.actor_layout, parent, false); 
...

actor_layout.xml:

<LinearLayout 
android:id="@+id/linLayoutActor"
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:layout_width="match_parent"
android:layout_height="wrap_content" >

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

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
            <ImageView
                android:id="@+id/ImageViewActor"
                android:layout_width="130dp"
                android:layout_height="130dp"
                android:padding="15dp" />

                <TextView
                    android:id="@+id/textViewActorName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="15dp"
                    android:textColor="@android:color/holo_blue_light"
                    android:textSize="20sp"
                    android:textStyle="bold" />

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

I am receiving this error:

    01-24 02:16:37.660: E/AndroidRuntime(2776): android.view.InflateException: Binary XML file line #10: Error inflating class android.support.v7.widget.CardView
01-24 02:16:37.660: E/AndroidRuntime(2776):     at android.view.LayoutInflater.createView(LayoutInflater.java:633)
01-24 02:16:37.660: E/AndroidRuntime(2776):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
01-24 02:16:37.660: E/AndroidRuntime(2776):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
01-24 02:16:37.660: E/AndroidRuntime(2776):     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
01-24 02:16:37.660: E/AndroidRuntime(2776):     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
01-24 02:16:37.660: E/AndroidRuntime(2776):     at com.example.demojsonparsingimage1.ActorAdapter.getView(ActorAdapter.java:45)
Malwinder
  • 133
  • 2
  • 3
  • 10
  • Have you added the gradle dependency? It's packaged separate from appcompat, `com.android.support:cardview-v7:21.0.3` – darnmason Jan 23 '15 at 20:57
  • I am using Eclipse. How to add gradle dependency? – Malwinder Jan 23 '15 at 20:59
  • Ah sorry I thought it safe to assume most ppl are using Android Studio these days, I highly recommend it. – darnmason Jan 23 '15 at 21:00
  • @darnmason Can you tell me how to add gradle dependency to project in eclipse? – Malwinder Jan 23 '15 at 21:01
  • Gradle is the build system used by Android Studio, which is a separate IDE to Eclipse so doesn't apply to you. Only thing I can say is make sure you have the CardView library included in your Eclipse project. – darnmason Jan 23 '15 at 21:03
  • but there must exist a solution to add depndency to gradle in eclipse? – Malwinder Jan 23 '15 at 21:05
  • Gradle has nothing to do with Eclipse, here's instructions to add the library to Eclipse: http://stackoverflow.com/questions/26878803/how-to-add-android-support-v7-libraries-in-eclipse – darnmason Jan 23 '15 at 21:08

1 Answers1

0

To add CardView to an Eclipse Android project you need to add it as a library project. Should be in /extras/android/support/v7/cardview, Eclipse should be able to import it for you.

Mc Mike
  • 11
  • 2