java - 由于 androidx drawerlayout 导致的错误

标签 java android

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cn/com.example.cn.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class 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'    
}  

'''

最佳答案

错误很明显。您正在使用 Android Support Librariesdependencies但在 layout你正在尝试使用 androidx .

例如:

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

AndroidX: androidx.appcompat:appcompat:1.0.0

所以您有两个选项之一,要么继续使用 Android Support Libraries这意味着您需要重命名 DrawerLayout<android.support.v4.widget.DrawerLayout或将项目升级到 AndroidX .

要进行升级,您可以从 Android Studio 继续 Refactor -> Migrate to AndroidX 进行升级.

如果您决定使用这种方式,请遵循 Android Studio 提供的建议 zip您的项目,而不是进行升级。这意味着您始终可以在 AndroidX 之前返回您的项目升级。

Also there is possibility that not all things will work after upgrade and maybe manually adjustment will be needed.

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

关于java - 由于 androidx drawerlayout 导致的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55002637/

相关文章:

java - Spring 验证 : Requiring an exact length on an optional field

java - 部署后语言更改 - Android

java - FirebaseRecyclerAdapter 没有开始监听

java - 从http get请求中读取非英文字符

java - Android Volley 依赖

java - 在 HQL 中使用 boolean 值

java - 正则表达式中的匹配字符 * (Java)

java - 如何将变量从一个 JFrame 传递到另一个 JFrame

java - 通过上下文传递类名并使用它在不同的类中存储静态值

android - 生成签名的APK错误