0

I'm getting crash reports from users with Samsung Devices (Galaxy Note 10.1 2014 Edition (lt03wifi), Galaxy Note 10.1 2014 Edition (lt03lte), Galaxy Note3 (hlte), Galaxy Note3 Neo (hl3g) and others), all running Android 5.1. When the user presses the physical menu key within my app, the exception below is thrown. Other devices open the menu just fine and display it correctly.

android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:2452)
at android.content.res.Resources.getDrawable(Resources.java:1947)
at android.content.Context.getDrawable(Context.java:409)
at com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:810)
at com.android.internal.policy.impl.PhoneWindow.onKeyUpPanel(PhoneWindow.java:1092)
at com.android.internal.policy.impl.PhoneWindow.onKeyUp(PhoneWindow.java:2179)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2625)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4881)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4836)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4300)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4353)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4319)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4445)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4327)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4502)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4300)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4353)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4319)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4327)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4300)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4353)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4319)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4478)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4720)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2811)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:2403)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:2394)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2788)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:143)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:6873)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

How can this behaviour be fixed?

My Activity onCreateOptionsMenu:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_develop, menu);
    StyleApp.styleMenu(menu,this);
    return true;
}

The styleMenu function:

public static void styleMenu(Menu menu,Context c) {
    ColorFilter colorFilter = getColorFilter(c);

    for(int i=0;i<menu.size();i++){
        MenuItem item=menu.getItem(i);
        Drawable icon=item.getIcon();
        icon.setColorFilter(colorFilter);
    }
}
TSGames
  • 679
  • 11
  • 25
  • I faced similar issue for LG devices. Can you check this issue on GitHub? https://github.com/midhunhk/message-counter/issues/6. The solution was based on this answer http://stackoverflow.com/a/27024610/592025 – midhunhk Mar 01 '16 at 10:53
  • Thanks for your hint midhunhk! But the LG bug seems different, since it throws a NullPointerException and this one is a Resources$NotFoundException. – TSGames Mar 01 '16 at 13:15
  • Resource ID #0x0 looks interesting. Can you check your R.java and see if this is there? Is there any chance a resource is missing in a different variant resource file, like api or screen width etc.. ? – midhunhk Mar 01 '16 at 13:41
  • Hope you didn't have situation like http://stackoverflow.com/a/20177019/592025 . – midhunhk Mar 01 '16 at 13:42
  • 1
    0x0 means that the pointer to the resource is probably invalid, there should be no resource with a id of zero. I just inflate the menu with Android (Menu xml and menu inflater), and as mentioned, all other devices display it just fine. – TSGames Mar 01 '16 at 16:12
  • @TSGames, post your code as well – Hiren Patel Mar 10 '16 at 08:22
  • Can you post the code that is being executed when the user presses the menu button? – DDsix Mar 16 '16 at 12:06
  • Yes, I'll post some more code! – TSGames Mar 18 '16 at 11:01

2 Answers2

0

As per my mindset application having issue with Resources.

If you are accessing Resources by pressing Menu key, use below code to prepare resources.

DisplayMetrics mMetrics = new DisplayMetrics();
Activity act = (Activity)mContext;
mContext.getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
AssetManager mgr = context.getAssets();
Resources mResources = new Resources(mgr, mMetrics, act.getResources().getConfiguration());

Now access here resource,

Say for example:

String color = mResources.getString(R.string.application_name);

Hope this would help you.

Hiren Patel
  • 52,124
  • 21
  • 173
  • 151
0

I finally fixed it by replacing my Theme parent from

<style name="MyTheme" parent="@android:style/Theme.Material" />

to

<style name="MyTheme" parent="@android:style/Theme.DeviceDefault" />

in my theme.xml.

It seems like not all Samsung Devices support the Android Default Themes correctly.

TSGames
  • 679
  • 11
  • 25