I have been sporadically receiving crash reports from several of my activities relating to Resources$NotFoundException for various drawables. It only seems to happen on certain devices as I have never been able to replicate the crash on any device or emulator myself. I thought it might be related to some language setting on the device so I started collecting language data along with the crashes. So far I've received crashes from devices with language codes zh_CN and en_JM. Not sure if that is at all relevant. The particular drawable is contained within the folders drawable-hdpi, drawable-mdpi, drawable-xdpi, and drawable-xxdpi, but is not in drawable-ldpi.
The activity:
private void setupDrawerContent(NavigationView navView) {
navigationView = navView;
navigationView.setNavigationItemSelectedListener(this::selectDrawerItem);
// crashing on inflateMenu
navigationView.inflateMenu(R.menu.drawer_menu);
}
The layout file:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="@string/drawer_entries">
<menu>
<item
android:id="@+id/item_createEntry"
// the offending drawable ic_action_new
android:icon="@drawable/ic_action_new"
android:title="@string/drawer_crate_entry" />
</menu>
</item>
</menu>
The stack trace:
Caused by android.content.res.Resources$NotFoundException: Resource ID #0x7f080090
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
at android.content.res.Resources.getValue(Resources.java:1331)
at androidx.appcompat.widget.ResourceManagerInternal.createDrawableIfNeeded(ResourceManagerInternal.java:179)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:144)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:135)
at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:104)
at androidx.appcompat.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:505)
at com.google.android.material.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems(NavigationMenuPresenter.java:585)
at com.google.android.material.internal.NavigationMenuPresenter$NavigationMenuAdapter.update(NavigationMenuPresenter.java:546)
at com.google.android.material.internal.NavigationMenuPresenter.updateMenuView(NavigationMenuPresenter.java:128)
at com.google.android.material.navigation.NavigationView.inflateMenu(NavigationView.java:371)
at org.lakeobserver.observer.android.ui.activity.HomeActivity.setupDrawerContent(HomeActivity.java:314)
at org.lakeobserver.observer.android.ui.activity.HomeActivity.onCreate(HomeActivity.java:150)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)