简体   繁体   English

由于androidx抽屉布局而导致的错误

[英]Errors due to androidx drawerlayout

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 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">  

app 应用

''' “””

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'    
}  

''' “””

Check if you have added the dependency. 检查是否已添加依赖项。

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

Then use the tag android.support.v4.widget.DrawerLayout. 然后使用标记android.support.v4.widget.DrawerLayout。

I think You have defined the v4 version of drawer layout in your java class or kotlin class. 我认为您已经在java类或kotlin类中定义了v4版本的抽屉布局。 thats why its giving you error 那就是为什么它给你错误

Error is obvious. 错误很明显。 You are using Android Support Libraries in dependencies but in layout you are trying to use androidx . 您正在dependencies中使用Android Support Libraries ,但是在layout您尝试使用androidx

For example: 例如:

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

AndroidX: androidx.appcompat:appcompat:1.0.0 AndroidX: androidx.appcompat:appcompat:1.0.0

So you have one of the two options either continue using Android Support Libraries which means you need to rename DrawerLayout to <android.support.v4.widget.DrawerLayout or to upgrade project to AndroidX . 因此,您有两个选项之一,或者继续使用Android Support Libraries ,这意味着您需要将DrawerLayout重命名为<android.support.v4.widget.DrawerLayout或将项目升级到AndroidX

To make upgrade you can do that from Android Studio by going on Refactor -> Migrate to AndroidX . 要进行升级,您可以通过Refactor -> Migrate to AndroidX从Android Studio进行升级。

If you decide to use this way, follow suggestions provided by Android Studio it will zip your project and than make upgrade. 如果您决定使用这种方式,请遵循Android Studio提供的建议,它将zip您的项目,然后进行升级。 That means you can always return to your project before AndroidX upgrade. 这意味着您始终可以在升级AndroidX之前返回项目。

Also there is possibility that not all things will work after upgrade and maybe manually adjustment will be needed. 另外,升级后并非所有功能都可以正常运行,并且可能需要手动调整。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM