title: Calls to OnPrepareOptionsMenu yields null pointer exception
body: <p>Each time I call <code>getActivity().invalidateOptionsMenu();</code> My application will foreclose due to a null pointer exception.</p>
  
  <p>My goal is to change Action Settings based on the fragment that is called via the ListView within my Navigational Drawer.</p>
  
  <p>My OnPrepareOptionsMenu method is as follows:</p>
  
  <pre><code>public boolean onPrepareOptionsMenu(Menu menu) {
      super.onPrepareOptionsMenu(menu);
      if (mNumber == 1) {
          menu.findItem(R.id.sortByDivision).setVisible(false);
          menu.findItem(R.id.sortByFighter).setVisible(false);
      }
      if (mNumber == 2) {
          menu.findItem(R.id.sortByDivision).setVisible(false);
          menu.findItem(R.id.sortByFighter).setVisible(true);
      }
      if (mNumber == 3) {
          menu.findItem(R.id.sortByDivision).setVisible(true);
          menu.findItem(R.id.sortByFighter).setVisible(false);
      }
      if (mNumber == 4) {
          menu.findItem(R.id.sortByDivision).setVisible(false);
          menu.findItem(R.id.sortByFighter).setVisible(false);
      }
      return true;
      //return super.onPrepareOptionsMenu(menu);
  }
  </code></pre>
  
  <p>Calls to this method are as follows:</p>
  
  <pre><code>  @Override
              public void onDrawerClosed(View drawerView) {
                  super.onDrawerClosed(drawerView);
                  if (!isAdded()) {
                      return;
                  }
  
                  //getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
              }
  
              @Override
              public void onDrawerOpened(View drawerView) {
                  super.onDrawerOpened(drawerView);
                  if (!isAdded()) {
                      return;
                  }
  
                  if (!mUserLearnedDrawer) {
                      // The user manually opened the drawer; store this flag to prevent auto-showing
                      // the navigation drawer automatically in the future.
                      mUserLearnedDrawer = true;
                      SharedPreferences sp = PreferenceManager
                              .getDefaultSharedPreferences(getActivity());
                      sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
                  }
  
                  //getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
              }
          };
  </code></pre>
  
  <p>I can post more code or whole file if necessary.  My logcat points to the first menu.findItem… statement that is not commented out.</p>
  
  <pre><code>05-27 16:50:17.898  25117-25117/com.MMA E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.MMA, PID: 25117
      java.lang.NullPointerException
              at com.MMA.BMMA.onPrepareOptionsMenu(BMMA.java:129)
              at android.app.Activity.onPreparePanel(Activity.java:2564)
              at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:464)
              at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)
              at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)
              at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
              at android.view.Choreographer.doCallbacks(Choreographer.java:574)
              at android.view.Choreographer.doFrame(Choreographer.java:543)
              at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
              at android.os.Handler.handleCallback(Handler.java:733)
              at android.os.Handler.dispatchMessage(Handler.java:95)
              at android.os.Looper.loop(Looper.java:136)
              at android.app.ActivityThread.main(ActivityThread.java:5102)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>