JakeWharton/ActionBarSherlock — Issue #284: NullPointerException when trying to select menu option after it was not visible
Author: mattkranzler5
Created: 2012-02-18 01:58:15+00:00
State: open

I have a screen where by default a menu option is not visible. When changing to a different page in the view pager, the invalidateOptionsMenu() is called and it is set to visible. When trying to select the item, I am getting a NullPointerException. Here is the stack trace:

java.lang.NullPointerException
at com.android.internal.view.menu.MenuItemImpl.toString(MenuItemImpl.java:490)
at java.lang.StringBuilder.append(StringBuilder.java:202)
at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchOptionsItemSelected(ActionBarSherlockNative.java:75)
at android.support.v4.app.FragmentActivity.onOptionsItemSelected(FragmentActivity.java:283)
at android.app.Activity.onMenuItemSelected(Activity.java:2502)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:632)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:950)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:490)
at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:103)
at android.view.View.performClick(View.java:3480)
at android.view.View$PerformClick.run(View.java:13983)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)