【问题标题】:Missing classes android.support.v7.widget.CardView缺少类 android.support.v7.widget.CardView
【发布时间】:2020-02-13 20:53:21
【问题描述】:

我已经从 tutoriel 构建了文本识别应用程序,但我的布局给了我一些问题

找不到以下类:

android.support.v7.widget.CardView

Expectation result

Reality current result

我错过了什么或做错了什么?

build.gradle 应用程序

implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

activity_main

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardBackgroundColor="#fff"
            app:cardUseCompatPadding="true"
            app:cardCornerRadius="3dp"
            app:cardElevation="3dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="5dp">
                <TextView
                    android:text="Result"
                    android:textColor="@color/colorPrimary"
                    android:textSize="20sp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
                <EditText
                    android:id="@+id/resultET"
                    android:hint=""
                    android:autoLink="all"
                    android:padding="5dp"
                    android:background="@null"
                    android:textColor="#000"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:autofillHints=""/>
            </LinearLayout>
      </android.support.v7.widget.CardView>
   </LinearLayout>
 </ScrollView>
</RelativeLayout>

【问题讨论】:

    标签: android android-layout cardview gradle-dependencies


    【解决方案1】:

    除了替换

    com.android.support:cardview-v7:28.0.0
    

    作为

    androidx.cardview:cardview:1.0.0
    

    您仍然需要替换 xml 并从中导入对象

    android.support.v7.widget.CardView
    

    androidx.cardview.widget.CardView
    

    顺便说一句,其他组件也应该更换。 例如:

    在gradle中

    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    

    在代码和 xml 对象中将是

    androidx.recyclerview.widget.RecyclerView
    

    【讨论】:

      【解决方案2】:

      如果你在 androidx 下做你的项目,请替换

      implementation 'android.support.v7.widget.CardView'
      

      implementation'androidx.cardview:cardview:1.0.0'
      

      【讨论】:

      • 忘了告诉你需要更换所有相关的小部件
      【解决方案3】:

      在 Java 中 - 您现在可以使用

      导入androidx.cardview.widget.CardView;

      在 build.gradle -

      实现'androidx.cardview:cardview:1.0.0'

      【讨论】:

      • 如果您没有使用 android.useAndroidX=true 和 android.enableJetifier=true 请在 gradle.properties 文件中使用这些。此外,您在运行时或编译时也会收到此错误。也请提及。
      猜你喜欢
      • 1970-01-01
      • 2015-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-28
      相关资源
      最近更新 更多