2

I am trying to use a CardView in my fragment, but while I am creating the XML, I am getting a runtime error

Error inflating class android.support.v7.widget.CardView

when I change to that fragment. I have gone through the steps found on this stack overflow question (Error inflating class and android.support.v7.widget.CardView) to add the .jar file to my project and set up dependencies, but my program still crashes.

I am using Eclilpse if that makes any difference. My xml file is

fragment_layout_three.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="203dp"
        android:layout_height="139dp"
        android:text="Test" />

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


Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.pacificu.zeus.boxerapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="21" />

<permission
    android:name="edu.pacificu.zeus.boxerapp.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="edu.pacificu.zeus.boxerapp.permission.MAPS_RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

    <meta-data
         android:name="com.google.android.gms.version"
         android:value="@integer/google_play_services_version"/>

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyCNkCxSPo3n2sUuDIZmP_W6LSHQGwsYR88"/>

    <!--Splash Activity -->
    <activity
        android:name=".SplashScreen"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!--Main Activity-->
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
    </activity>
</application>

Community
  • 1
  • 1
Ryan Newman
  • 846
  • 3
  • 17
  • 35

1 Answers1

2

In my case i have to do both the things add android.support.v7.widget.CardView as a library project and also add + check it's jar file in java build path

  1. Go to File -> Import -> Existing Android code into workspace --> Browse (Go to sdk/extras/android/support/v7/cardview) --> Click ok --> Click Finish

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

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

  4. right click on your project again --> build path --> configure build path -->under libraries-->add jar-->expand cardview-->expand libs-->select android.support.v7.widget.CardView.jar

  5. under order and export-->check android.support.v7.widget.CardView.jar-->click ok