Andros Adrianopolos
Andros Adrianopolos

Reputation: 674

CardView class "could not be found" despite implementing it in the gradle file

For some reason, my CardView cannot find the class. I'm using it as the root layout and I have implemented it in the gradle file. I tried all the tips on SO but nothing works:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item_card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp"
    android:orientation="horizontal"
    card_view:cardCornerRadius="4dp">

    <TextView
        android:id="@+id/username_display"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/username_display" />

    <TextView
        android:id="@+id/password_display"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/password_display" />

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

This is the complete Gradle file:

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.ozbek.cryptpass"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
    implementation 'com.android.support:design:28.0.1'
    implementation 'com.google.android.material:material:1.1.0-alpha05'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha04'
    implementation 'com.android.support:cardview-v7:28.0.0'
    testImplementation 'junit:junit:4.13-beta-2'
    androidTestImplementation 'androidx.test:runner:1.2.0-alpha04'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha4'
}

And this is the error I'm getting:

The following classes could not be found:
- android.support.v7.widget.CardView (Fix Build Path, Edit XML, Create Class)

Upvotes: 1

Views: 652

Answers (1)

ismail alaoui
ismail alaoui

Reputation: 6073

your cardView doesn't show because there is nothing to show since you are setting its height="wrap_content" and the only children is empty , try to set your cardView height to 60dp to see if it will show something

    android:layout_height="60dp"

edit

as i can notice in your edit you are using androidx so you should use this :

 implementation 'androidx.cardview:cardview:1.1.0'

and in your xml file :

androidx.cardview.widget.CardView

if you want to use the old classes : add android:enableJetifier=true to your gradle.properties and use the appcompat dependencies instead.

Upvotes: 1

Related Questions