因此,约有1%的日常用户被NavigationView异常困扰,该异常是由于找不到图像资源引起的。我发现奇怪的是,其他用户中的99%都还不错。我希望在版本迭代中更新我的依赖关系能够解决问题本身,但是不幸的是,此错误已经在我的Crashlytics日志中保留了6个迭代,这是影响用户的最严重的崩溃。
显而易见的是,它特定于较旧的设备,但这是错误的假设。它不是特定于设备的,也不是特定于版本的。尽管可以指出一些细节
我使用的两个相关依赖性:
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
XML布局中的相关代码段:
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:headerLayout="@layout/layout_drawer_header2"
app:menu="@menu/navigation" />
标题布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/authWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
android:orientation="vertical"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
tools:layout_width="240dp">
<TextView
android:id="@+id/number"
style="@style/Base.TextAppearance.AppCompat.Display3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:fontFamily="sans-serif-medium"
android:textColor="?android:textColorPrimary"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="@+id/car"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/driver"
tools:text="#01" />
<ImageView
android:id="@+id/driverIcon"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
app:layout_constraintBottom_toBottomOf="@+id/driver"
app:layout_constraintStart_toEndOf="@+id/number"
app:layout_constraintTop_toTopOf="@+id/driver"
app:srcCompat="@drawable/ic_person_white_24dp" />
<TextView
android:id="@+id/driver"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"
android:layout_marginTop="16dp"
android:drawablePadding="8dp"
android:ellipsize="end"
android:lines="1"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Body1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/driverIcon"
app:layout_constraintTop_toTopOf="parent"
tools:text="Drivers name" />
<ImageView
android:id="@+id/coDriverIcon"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
app:layout_constraintBottom_toBottomOf="@+id/codriver"
app:layout_constraintStart_toEndOf="@+id/number"
app:layout_constraintTop_toTopOf="@+id/codriver"
app:srcCompat="@drawable/ic_person_white_24dp" />
<TextView
android:id="@+id/codriver"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"
android:drawablePadding="8dp"
android:ellipsize="end"
android:lines="1"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Body1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/coDriverIcon"
app:layout_constraintTop_toBottomOf="@+id/driver"
tools:text="Co-Driver name" />
<ImageView
android:id="@+id/carIcon"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
app:layout_constraintBottom_toBottomOf="@+id/car"
app:layout_constraintStart_toEndOf="@+id/number"
app:layout_constraintTop_toTopOf="@+id/car"
app:srcCompat="@drawable/ic_car_white_24dp" />
<TextView
android:id="@+id/car"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"
android:ellipsize="end"
android:lines="1"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Body1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/carIcon"
app:layout_constraintTop_toBottomOf="@+id/codriver"
tools:text="Racing Car" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<ImageView
android:id="@+id/image"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:srcCompat="@drawable/ic_account_circle_white_24dp" />
<ImageView
android:id="@+id/logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="12dp"
android:tint="@android:color/white"
app:srcCompat="@drawable/ic_log_out" />
</RelativeLayout>
<TextView
android:id="@+id/switchText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:layout_marginRight="8dp"
android:autoLink="web"
android:gravity="center_vertical"
android:maxLines="2"
android:text="@string/track_me_on_racelivemaps_com"
app:layout_constraintEnd_toStartOf="@+id/trackingOn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/number" />
<Switch
android:layout_width="wrap_content"
android:id="@+id/trackingOn"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content"
android:padding="8dp"
android:autoLink="web"
android:gravity="center_vertical"
android:maxLines="2"
app:layout_constraintBottom_toBottomOf="@+id/switchText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/switchText" />
<TextView
android:id="@+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:text="@string/active_stage"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Body2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/switchText" />
<Spinner
android:id="@+id/activeStage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView12" />
</androidx.constraintlayout.widget.ConstraintLayout>
菜单:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="@string/mode">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/recce"
android:icon="@drawable/ic_write_black_24dp"
android:title="@string/reccemode" />
<item
android:id="@+id/liaison"
android:icon="@drawable/ic_route_black_24dp"
android:title="@string/liaisonmode" />
<item
android:id="@+id/racing"
android:icon="@drawable/ic_racing_flag_black_24dp"
android:title="@string/racemode" />
<item
android:id="@+id/tsd"
android:icon="@drawable/ic_timer_black_24dp"
android:title="@string/tsd" />
<item
android:id="@+id/tsd_advanced"
android:icon="@drawable/ic_tsd_advanced"
android:title="@string/tsd_advanced" />
<item
android:id="@+id/custom_1"
android:icon="@drawable/ic_navigation_layout"
android:title="@string/custom_layout_1" />
<item
android:id="@+id/custom_2"
android:icon="@drawable/ic_navigation_layout"
android:title="@string/custom_layout_2" />
<item
android:id="@+id/custom_3"
android:icon="@drawable/ic_navigation_layout"
android:title="@string/custom_layout_3" />
</group>
</menu>
</item>
<group android:checkableBehavior="none">
<item
android:id="@+id/stages"
android:icon="@drawable/ic_stage_black_24dp"
android:title="@string/special_stages" />
<item
android:id="@+id/settings"
android:icon="@drawable/ic_settings_black_24dp"
android:title="@string/settings" />
<item
android:id="@+id/customize_ui"
android:icon="@drawable/ic_layout_edit"
android:title="@string/customize_ui" />
<item
android:id="@+id/weather"
android:icon="@drawable/ic_weather"
android:title="@string/weather" />
<item
android:id="@+id/login"
android:icon="@drawable/ic_key_white_24dp"
android:title="@string/log_in" />
<item
android:id="@+id/manual"
android:icon="@drawable/ic_manual"
android:title="@string/user_manual" />
<item
android:id="@+id/language"
android:icon="@drawable/ic_translate"
android:title="@string/language" />
<item
android:id="@+id/invite"
android:icon="@drawable/ic_share_black_24dp"
android:title="@string/invite" />
<item
android:id="@+id/feedback"
android:icon="@drawable/ic_feedback_black_24dp"
android:title="@string/feedback_report_bug" />
<item
android:id="@+id/tester"
android:icon="@drawable/ic_tester"
android:title="@string/become_a_tester" />
<item
android:id="@+id/policy"
android:icon="@drawable/ic_policy"
android:title="@string/privacy_policy" />
<item
android:id="@+id/logoff"
android:icon="@drawable/ic_key_white_24dp"
android:title="@string/log_off" />
<item
android:id="@+id/exit"
android:icon="@drawable/ic_exit_to_app_black_24dp"
android:title="@string/exit" />
</group>
</menu>
最后是崩溃日志。
android.view.InflateException:二进制XML文件行#48:二进制XML 文件行#48:错误膨胀类 com.google.android.material.navigation.NavigationView 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3173) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3284) 在android.app.ActivityThread.-wrap12(未知来源) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1894) 在android.os.Handler.dispatchMessage(Handler.java:109) 在android.os.Looper.loop(Looper.java:166) 在android.app.ActivityThread.main(ActivityThread.java:7383) 在java.lang.reflect.Method.invoke(Method.java) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:469) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
由android.view.InflateException引起:二进制XML文件第48行: 二进制XML文件第48行:膨胀类错误 com.google.android.material.navigation.NavigationView
由android.view.InflateException引起:二进制XML文件第48行: 错误膨胀类 com.google.android.material.navigation.NavigationView
由java.lang.reflect.InvocationTargetException引起 在java.lang.reflect.Constructor.newInstance0(Constructor.java) 在java.lang.reflect.Constructor.newInstance(Constructor.java:334) 在android.view.LayoutInflater.createView(LayoutInflater.java:658) 在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801) 在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 在android.view.LayoutInflater.rInflate(LayoutInflater.java:874) 在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835) 在android.view.LayoutInflater.inflate(LayoutInflater.java:515) 在android.view.LayoutInflater.inflate(LayoutInflater.java:423) 在android.view.LayoutInflater.inflate(LayoutInflater.java:374) 在androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 在androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 在ee.siimplangi.rallytripmeter.activities.MainActivity.onCreate(MainActivity.kt:186) 在android.app.Activity.performCreate(Activity.java:7358) 在android.app.Activity.performCreate(Activity.java:7349) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1219) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3126) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3284) 在android.app.ActivityThread.-wrap12(未知来源) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1894) 在android.os.Handler.dispatchMessage(Handler.java:109) 在android.os.Looper.loop(Looper.java:166) 在android.app.ActivityThread.main(ActivityThread.java:7383) 在java.lang.reflect.Method.invoke(Method.java) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:469) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
由android.view.InflateException引起:二进制XML文件第29行: 二进制XML文件第29行:膨胀类ImageView时出错
由android.view.InflateException引起:二进制XML文件第29行: 膨胀类ImageView时出错
由android.content.res.Resources $ NotFoundException:资源ID
引起0x7f0800a5
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:290) at android.content.res.Resources.getValue(Resources.java:1476) at androidx.appcompat.widget.AppCompatDrawableManager.createDrawableIfNeeded(AppCompatDrawableManager.java:235) at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200) at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191) at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102) at androidx.appcompat.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59) at androidx.appcompat.widget.AppCompatImageView.(AppCompatImageView.java:78) at androidx.appcompat.widget.AppCompatImageView.(AppCompatImageView.java:68) at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182) at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106) at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266) at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:783) 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 com.google.android.material.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:207) at com.google.android.material.navigation.NavigationView.inflateHeaderView(NavigationView.java:281) at com.google.android.material.navigation.NavigationView.(NavigationView.java:193) at com.google.android.material.navigation.NavigationView.(NavigationView.java:104) at java.lang.reflect.Constructor.newInstance0(Constructor.java) 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.setContentView(AppCompatDelegateImpl.java:469) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at ee.siimplangi.rallytripmeter.activities.MainActivity.onCreate(MainActivity.kt:186) at android.app.Activity.performCreate(Activity.java:7358) at android.app.Activity.performCreate(Activity.java:7349) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1219) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3126) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3284) at android.app.ActivityThread.-wrap12(Unknown Source) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1894) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7383) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
答案 0 :(得分:1)
在阅读注释之后,首先您必须使用android:src
,因为您没有使用矢量可绘制。
当我们将资源管理器中的图像粘贴到 drawable 文件夹中,然后询问是否要复制 drawable 或 drawable-v24 时,是否发生此问题?在两个目录结构中都粘贴了图像,或者在另一个目录结构中又粘贴了一个图像,则将显示此错误,请确保将图标移至 drawable 后将其从 drawable-v24 中删除/ strong>文件夹,然后清理项目,然后运行它就可以了。