Search code examples
androidsamsung-mobileappbar

Getting Resources$NotFoundException when testing application on samsung s2


My application is being tested on Samsung S2 having 4.1.2 and its keep crashing without any reason. This application is working on other mobiles having 4.2+ android versions and working fine with on them but its crashing on this mobile (or i think having this version).

Here is the logcat

FATAL EXCEPTION: main
               android.content.res.Resources$NotFoundException: Resource ID #0x7f0200e8
                   at android.content.res.Resources.getValue(Resources.java:1026)
                   at android.content.res.Resources.getDrawable(Resources.java:671)
                   at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
                   at android.support.v7.widget.TintManager.getDrawable(TintManager.java:147)
                   at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
                   at android.support.v7.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:114)
                   at android.support.v7.widget.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:206)
                   at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:182)
                   at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192)
                   at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:451)
                   at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138)
                   at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
                   at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229)
                   at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284)
                   at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030)
                   at android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1053)
                   at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:449)
                   at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:60)
                   at android.os.Handler.handleCallback(Handler.java:615)
                   at android.os.Handler.dispatchMessage(Handler.java:92)
                   at android.os.Looper.loop(Looper.java:137)
                   at android.app.ActivityThread.main(ActivityThread.java:4921)
                   at java.lang.reflect.Method.invokeNative(Native Method)
                   at java.lang.reflect.Method.invoke(Method.java:511)
                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
                   at dalvik.system.NativeStart.main(Native Method)

Solution

  • The API dependent folders that you confirmed in the comments mean that the resource you are trying to access can only be accessed by the API level (or higher) that is indicated on the folder. So if you have the resource you are trying to access in a folder like drawables-v17 then this means that the drawable can only be accessed by API 17 and higher (Android 4.2+). Android 4.1 won't be able to access it so you will have the NotFoundException that you see here. If you put the resource in a folder unrelated to any API levels (ie, just drawables) it should be fine.