Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Didn't find class "android.support.v7.widget.CardView"

I have seen a lot of questions like this on here and they all have the same answer, make sure you have

compile 'com.android.support:cardview-v7:26.0.0'

in you build.gradle file, and make sure you are using the fully qualified name in your xml...

<android.support.v7.widget.CardView

I am using that in my xml file, and I have the compile line in my build.gradle file. The app compiles, but whenever I run the app on the emulator, I click the button to launch the ShowImagesActivity, it crashes with the message "Didn't find class 'android.support.v7.widget.CardView' on path..."

Here is my layout_images.xml file...

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

    <adroid.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:padding="8dp">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="100dp">
            <TextView
                android:id="@+id/textViewName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Name"
                android:textAlignment="center" />
            <ImageView
                android:id="@+id/imageView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/textViewName" />
        </RelativeLayout>
    </adroid.support.v7.widget.CardView>

</LinearLayout>

And here is my build.gradle file, the app one...

apply plugin: 'com.android.application'
check.dependsOn 'assembleMinSdkJellybeanDebugAndroidTest', 'assembleMinSdkIcsDebugAndroidTest'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.0'
    flavorDimensions "minSdkVersion"

    defaultConfig {
        applicationId "com.google.firebase.quickstart.auth"
        minSdkVersion 26
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }

    productFlavors {
        // Build variant with minSdk 16 to include Facebook and FirebaseUI libraries.
        minSdkJellybean {
            dimension "minSdkVersion"
            minSdkVersion 16
        }
        // Build variant with minSdk 14, excludes Facebook and FirebaseUI libraries.
        minSdkIcs {
            dimension "minSdkVersion"
            minSdkVersion 16
        }
    }
}

configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:26.0.0'
}

dependencies {
    // Firebase Authentication
    // Google Sign In SDK (only required for Google Sign In)
    // Firebase UI
    // Used in FirebaseUIActivity. The FirebaseUI-Android library has a minSdk level of 16
    // so this library is only included in the minSdkJellybean variant.
    // Facebook Android SDK (only required for Facebook Login)
    // Used in FacebookLoginActivity. This is only compiled into the minSdkJellybean variant of this
    // app. You can build a 'minSdkGingerbread' variant to test on devices with 9 <= SDK <= 15.
    // Twitter Android SDK (only required for Twitter Login)
    compile('com.twitter.sdk.android:twitter-core:1.6.6@aar') {
        transitive = true
    }
    compile('com.twitter.sdk.android:twitter:1.13.1@aar') {
        transitive = true
    }
    compile 'com.google.firebase:firebase-storage:11.2.0'
    compile 'com.google.firebase:firebase-storage:11.2.0'
    compile 'com.android.support:appcompat-v7:26.0.0'
    compile 'com.android.support:animated-vector-drawable:26.0.0'
    compile 'com.android.support:cardview-v7:26.0.0'
    compile 'com.android.support:recyclerview-v7:26.0.0'
    compile 'com.android.support:design:26.0.0'
    compile 'com.firebaseui:firebase-ui:2.3.0'
    compile 'com.google.firebase:firebase-auth:11.2.0'
    compile 'com.google.android.gms:play-services-auth:11.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-database:11.2.0'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
    androidTestCompile 'com.android.support.test:runner:0.5'
    minSdkJellybeanCompile 'com.facebook.android:facebook-android-sdk:4.9.0'
    minSdkJellybeanCompile 'com.android.support:customtabs:26.0.0'
}

apply plugin: 'com.google.gms.google-services'

In my code I am using

@Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View                    v          = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_images, parent, false);
        ViewHolder viewHolder = new ViewHolder(v);
        return viewHolder;
    }

I have everything that all of the other posts say I need, the compile line in my build.gradle and the fully qualified name in my xml view, and the app compiles perfectly, it just crashes whenever I try to run it on the emulator after I click the button that starts the ShowImagesActivity. Shouldn't it fail to compile if it can't find the class? Is there any other solution, or can anyone see anything that is wrong that would make the app crash by not being able to find the class? Thank you.

like image 797
Neglected Sanity Avatar asked Dec 02 '22 11:12

Neglected Sanity


2 Answers

I had the same issue but my library is updated to androidX

implementation 'androidx.cardview:cardview:1.0.0'

Therefore my issue was solved by using the tag

<androidx.cardview.widget.CardView/>
like image 79
Haseeb Hassan Asif Avatar answered Dec 04 '22 11:12

Haseeb Hassan Asif


Check your typing, you are missing an 'n' in the XML

<adroid.support.v7.widget.CardView ...
like image 44
Chisko Avatar answered Dec 04 '22 11:12

Chisko