2

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)
brassmookie
  • 104
  • 6
  • 1
    It will be helpful if you can note in which directories are `ic_action_new` defined, to determine if there are configurations where the Android fallback logic may fallback to undefined. In the meantime, maybe you can look at https://stackoverflow.com/questions/10685466/android-resources-best-match-fallback-logic to check if your resource definition has some gaps yourself. – Maurice Lam Jan 17 '22 at 22:27
  • @maurice just updated the question to include those details – brassmookie Jan 18 '22 at 03:08
  • @brassmookie any luck with solving this? – Bassel Mourjan Jul 20 '23 at 06:26
  • @BasselMourjan unfortunately not. I still get the crash reports coming though my crashlytics sporadically. I started sending additional user data with the crash reports like screen size and network connectivity, hoping to find a pattern, but no such luck. – brassmookie Jul 28 '23 at 15:35
  • @brassmookie thank you for taking the time and letting me know.. I will make sure to share any news/solutions if i come across.. cheers – Bassel Mourjan Jul 29 '23 at 08:13

0 Answers0