Android MaterialCardView导致充气异常
每当我运行我的应用程序时,我的应用程序都会崩溃,Logcat中显示以下异常Android MaterialCardView导致充气异常,android,inflate-exception,Android,Inflate Exception,每当我运行我的应用程序时,我的应用程序都会崩溃,Logcat中显示以下异常 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flickr/com.example.flickr.PhotoDetailActivity}: android.view.InflateException: Binary XML file line #25: Binary XML file line #14: Er
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flickr/com.example.flickr.PhotoDetailActivity}: android.view.InflateException: Binary XML file line #25: Binary XML file line #14: Error inflating class androidx.cardview.widget.MaterialCardView
此XML文件(PhotoDetailActivity)导致此膨胀异常
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:cardCornerRadius="16dp"
app:cardElevation="4dp">
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
我不知道为什么会这样
有人能帮我解决这个错误吗?你确定你的应用程序主题使用了材质主题作为父对象吗?@PraveenSP抱歉,我没有得到它。我是android开发新手。请尝试将
android:theme=“@style/theme.MaterialComponents.Light”
添加到it@Blackbelt对现在它运行良好。你能告诉我为什么我们要增加这一行吗?这似乎是图书馆的要求。您可以将其作为它们提供给视图,也可以作为应用程序使用它们()您确定您的应用程序主题将材质主题用作父级吗?@PraveenSP抱歉,我没有得到它。我是android开发新手。请尝试将android:theme=“@style/theme.MaterialComponents.Light”
添加到it@Blackbelt对现在它运行良好。你能告诉我为什么我们要增加这一行吗?这似乎是图书馆的要求。要么将其作为它们提供给视图,要么将其作为应用程序使用()
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.flickr"
minSdkVersion 21
targetSdkVersion 29
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'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.2.2'
implementation 'androidx.navigation:navigation-ui:2.2.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.squareup.picasso:picasso:2.71828'
}