Класс CardView "не найден", несмотря на то, что он реализован в файле gradle - PullRequest
1 голос
/ 28 апреля 2019

По какой-то причине мой CardView не может найти класс.Я использую его в качестве корневого макета, и я реализовал его в файле Gradle.Я перепробовал все советы по SO, но ничего не работает:

<?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>

Это полный файл Gradle:

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'
}

И вот эта ошибка, которую я получаю:

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

1 Ответ

1 голос
/ 28 апреля 2019

ваш cardView не отображается, потому что нечего показывать, так как вы устанавливаете его height="wrap_content", а единственный дочерний элемент пуст, попробуйте установить cardView высоту на 60dp, чтобы увидеть, покажется ли ончто-то

    android:layout_height="60dp"

edit

, поскольку я могу заметить, что в ваших изменениях вы используете androidx, поэтому вы должны использовать это:

 implementation 'androidx.cardview:cardview:1.1.0'

и в вашем XML-файле:

androidx.cardview.widget.CardView

, если вы хотите использовать старые классы: добавьте android:enableJetifier=true к вашему gradle.properties и используйте взамен appcompat.

...