gpt4 book ai didi

android - 迁移到 AndroidX 后,膨胀类 com.google.android.material.navigation.NavigationView 时出错

转载 作者:行者123 更新时间:2023-12-02 16:06:51 27 4
gpt4 key购买 nike

当我将项目更新为 AndroidX 并将 targetSdkVersion 设置为 28 后,从商店安装它进行 Beta 测试时,我的项目崩溃了。

以下是我收到的错误日志:

2019-07-08 08:28:33.026 32011-32011/? E/AndroidRuntime: FATAL EXCEPTION: main Process: hu.itq.oakprotection, PID: 32011
java.lang.RuntimeException: Unable to start activity ComponentInfo{hu.itq.oakprotection/hu.itq.oakprotection.MainActivity}: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:658)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.c(Unknown Source:23)
at androidx.appcompat.app.AppCompatActivity.setContentView(Unknown Source:4)
at hu.itq.oakprotection.MainActivity.onCreate(Unknown Source:6)
at android.app.Activity.performCreate(Activity.java:7372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.NoSuchMethodError: No interface method d()I in class Lorg/xmlpull/v1/XmlPullParser; or its super classes (declaration of 'org.xmlpull.v1.XmlPullParser' appears in /system/framework/core-libart.jar)
at androidx.appcompat.view.SupportMenuInflater.a(Unknown Source:5)
at androidx.appcompat.view.SupportMenuInflater.inflate(Unknown Source:25)
at com.google.android.material.navigation.NavigationView.b(Unknown Source:12)
at com.google.android.material.navigation.NavigationView.<init>(Unknown Source:255)
at com.google.android.material.navigation.NavigationView.<init>(Unknown Source:2)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:334) 

以下是我在 build.gradle 文件中的依赖项:

android {
compileSdkVersion 28
def versionMajor = 1
def versionMinor = 0
def versionPatch = 1
def versionBuild = 4 // ezt kell átírni új verzió kirakásakor

defaultConfig {
applicationId "hu.itq.oakprotection"
minSdkVersion 23
targetSdkVersion 28
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation 'androidx.core:core:1.0.2'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.annotation:annotation:1.1.0'

implementation 'com.payumoney.sdkui:plug-n-play:1.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'androidx.browser:browser:1.0.0'
implementation 'com.google.android.gms:play-services-base:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Test error miatt kellett
implementation 'androidx.annotation:annotation:1.1.0'

//Aszinkron hálózatokhoz
implementation 'com.android.volley:volley:1.1.1'

//Facebook
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
//Osm Droid
implementation 'org.osmdroid:osmdroid-android:6.1.0'
implementation 'com.github.MKergall:osmbonuspack:6.4'

implementation 'com.github.angads25:filepicker:1.1.1'
//Tile provider igényli
implementation 'mil.nga.geopackage:geopackage-android:3.0.2'
implementation 'com.j256.ormlite:ormlite-android:5.1'
implementation 'mil.nga.geopackage:geopackage-core:3.0.2'
implementation 'ar.com.hjg:pngj:2.1.0'
implementation 'mil.nga:tiff:2.0.0'
implementation('mil.nga.geopackage:geopackage-android:3.0.2') {
exclude group: 'com.google.android.gms', module: 'play-services'
exclude group: 'com.google.maps.android', module: 'android-maps-utils'
exclude group: 'com.android.support', module: 'support-v13'
}
//Glide
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
//Mapsforge rendering and database support, which is LGPL
implementation 'org.mapsforge:mapsforge-map-android:0.8.0'
implementation 'org.mapsforge:mapsforge-map:0.8.0'
implementation 'org.mapsforge:mapsforge-themes:0.8.0'
// ExoPlayer
implementation 'com.google.android.exoplayer:exoplayer:2.7.3'
//Youtube
implementation 'com.github.HaarigerHarald:android-youtubeExtractor:v1.7.0'}

activity_main.xml:

<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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context=".MainActivity">

<include
layout="@layout/app_bar_main" />

<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
app:itemIconTint="@color/colorPrimary"
app:itemTextColor="@color/colorPrimary"
android:backgroundTint="@color/colorWhite"/>

</androidx.drawerlayout.widget.DrawerLayout>

为什么我收到 NavigationViewandroid.view.InflateException 错误?

最佳答案

发生此错误的原因有多种。检查以下各项并确保它们正确:

  • 检查您的代码,了解您使用过的 com.google.android.material.navigation.NavigationView 中使用的 drawablecolor 资源,如果您使用的是 Android Studio 中的默认抽屉导航模板代码,则可能位于 activity_main.xml 中。
  • 检查可绘制文件是否位于 res/drawable 文件夹中,而不是位于 res/drawable-v21 中。
  • 检查您是否在 NavigationView 中使用了 android:backgroundTint()android:src 或类似函数。由于它们在 Android API 级别 21 以下无法工作,因此请改用 app:backgroundTintapp:srcCompat

关于android - 迁移到 AndroidX 后,膨胀类 com.google.android.material.navigation.NavigationView 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56931348/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com