簡體   English   中英

由於androidx抽屜布局而導致的錯誤

[英]Errors due to androidx drawerlayout

java.lang.RuntimeException:無法啟動活動ComponentInfo {com.example.cn/com.example.cn.MainActivity}:android.view.InflateException:二進制XML文件第2行:二進制XML文件第2行:膨脹類錯誤android.support.v4.widget.DrawerLayout

<?xml version="1.0" encoding="utf-8"?>  
<androidx.drawerlayout.widget.DrawerLayout  
xmlns:android="http://schemas.android.com/apk/res/android"  
xmlns:app="http://schemas.android.com/apk/res-auto"  
xmlns:tools="http://schemas.android.com/tools"  
android:id="@+id/drawable_layout"  
android:layout_width="match_parent"  
android:layout_height="match_parent"  
android:paddingLeft="10dp"  
android:paddingBottom="5dp"  
tools:context="com.example.cn.MainActivity"  
android:paddingStart="10dp"  
tools:ignore="RtlSymmetry">  

應用

“””

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.cn"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])  
//noinspection GradleCompatible  
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'  
implementation 'com.google.android.material:material:1.1.0-alpha04'  
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'  
implementation 'de.hdodenhof:circleimageview:3.0.0'  
implementation 'com.google.firebase:firebase-core:16.0.7'  
implementation 'com.google.firebase:firebase-auth:16.1.0'  
implementation 'com.google.firebase:firebase-messaging:17.4.0'  
apply plugin: 'com.google.gms.google-services'  
implementation 'com.firebaseui:firebase-ui-database:4.3.1'  
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'  
implementation 'com.squareup.picasso:picasso:2.71828'  
implementation 'com.google.firebase:firebase-database:16.1.0'  
implementation 'com.google.firebase:firebase-storage:16.1.0'  
testImplementation 'junit:junit:4.12'  
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'  
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-   
alpha01'  
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha02'    
}  

“””

檢查是否已添加依賴項。

dependencies {
   implementation 'com.android.support:appcompat-v7:28.0.0'
   implementation 'com.android.support:design:28.0.0'
}

然后使用標記android.support.v4.widget.DrawerLayout。

我認為您已經在java類或kotlin類中定義了v4版本的抽屜布局。 那就是為什么它給你錯誤

錯誤很明顯。 您正在dependencies中使用Android Support Libraries ,但是在layout您嘗試使用androidx

例如:

Android支持Libray: com.android.support:appcompat-v7 : com.android.support:appcompat-v7

AndroidX: androidx.appcompat:appcompat:1.0.0

因此,您有兩個選項之一,或者繼續使用Android Support Libraries ,這意味着您需要將DrawerLayout重命名為<android.support.v4.widget.DrawerLayout或將項目升級到AndroidX

要進行升級,您可以通過Refactor -> Migrate to AndroidX從Android Studio進行升級。

如果您決定使用這種方式,請遵循Android Studio提供的建議,它將zip您的項目,然后進行升級。 這意味着您始終可以在升級AndroidX之前返回項目。

另外,升級后並非所有功能都可以正常運行,並且可能需要手動調整。

或手動: https : //developer.android.com/jetpack/androidx/migrate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM