Java 我的xml代码中有一个错误,导致所有应用程序停止

Java 我的xml代码中有一个错误,导致所有应用程序停止,java,android,android-cardview,Java,Android,Android Cardview,我有一个错误,这是我的代码 dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:juni

我有一个错误,这是我的代码

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'androidx.cardview:cardview:1.0.0'
而对于xml

<android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="293dp"
            app:cardBackgroundColor="@color/card"
            app:cardCornerRadius="10dp"
            app:cardElevation="5dp"
            app:cardUseCompatPadding="true">

            <TextView
                android:id="@+id/textView4"
                android:layout_width="432dp"
                android:layout_height="510dp"
                android:text="TextView" />

            <WebView
                android:id="@+id/webview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:ignore="WebViewLayout" />
        </android.support.v7.widget.CardView>


有了这几行代码,应用程序停止了,我只尝试了依赖项行,而没有放XML的代码行,只有依赖项实现cardview行和hid没有停止,但当我将XML文件的代码行放入应用程序时,应用程序停止。

您的gradle文件中有
androidx
版本的
cardview

但您在布局文件中使用的是旧版本的
cardwiew


您必须在这两个版本中使用相同的版本。因此,将布局文件中的标记替换为:

<androidx.cardview.widget.CardView ... />


一般来说,如果您在
adb logcat
中包含stacktrace的确切文本,您将获得更多帮助
<android.support.v7.widget.CardView ... />
<androidx.cardview.widget.CardView ... />