title: I got java.lang.NullPointerException when i implement visibility on menu item
body: <p>ive been working on this a couple of days but to no luck.i am implementing the visibility of the menu item according to its session of state change of facebook and my app.</p>
  
  <p>I just need to hide the menu item on my login activity then once access is authenticated it will show of course the menu itself. </p>
  
  <p>I got one activity only:</p>
  
  <p>for the menu code:</p>
  
  <pre><code> @SuppressLint({ "InlinedApi", "NewApi" })
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          super.onCreateOptionsMenu(menu);
          getMenuInflater().inflate(R.menu.main, menu);
  
  
     menu.findItem(R.id.action_previous).setEnabled(viewPager.getCurrentItem() &gt; 0);
  
          // Add either a "next" or "finish" button to the action bar, depending on which page
          // is currently selected.
     MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,    (viewPager.getCurrentItem() == adapter.getCount() - 1)
                          ? R.string.action_finish
                          : R.string.action_next);
  
          item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
  
        menu1 = menu;
          return true;
  
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int itemId = item.getItemId();
          if (itemId == R.id.action_previous) {
              // Go to the previous step in the wizard. If there is no previous step,
              // setCurrentItem will do nothing.
              viewPager.setCurrentItem(viewPager.getCurrentItem() - 1);
              return true;
          } else if (itemId == R.id.action_next) {
              // Advance to the next step in the wizard. If there is no next step, setCurrentItem
              // will do nothing.
              viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
  
  
   *************************
  
    ViewPager viewPager;
   PagerAdapter adapter;
  //  public int mState = 1;
   Menu menu1;
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      setupFacebookConnect(savedInstanceState);
  
  
  
      int[] bookCover = new int[] { 
  
          R.drawable.image1, 
          R.drawable.image2,
          R.drawable.image3, 
  
      };
  
      // Locate the ViewPager in viewpager_main.xml
      viewPager = (ViewPager) findViewById(R.id.pager);
      // Pass results to ViewPagerAdapter Class
      adapter = new ViewPagerAdapter(this, bookCover);
      // Binds the Adapter to the ViewPager
      viewPager.setAdapter(adapter);
      viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
  
          @SuppressLint("NewApi")
          @Override
          public void onPageSelected(int position) {
           // When changing pages, reset the action bar actions since they are dependent
           // on which page is currently active. An alternative approach is to have each
           // fragment expose actions itself (rather than the activity exposing actions),
           // but for simplicity, the activity provides the actions in this sample.
              //mState = 1;
          invalidateOptionsMenu();
          }
  
      });
  
  
  
  
      Button facebook_connect = (Button) findViewById(R.id.facebook_login);
      facebook_connect.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              if (isFacebookConnected()) {
                  disConnectFacebook();
              } else {
                  connectFacebook();
              }
  
          }
      });
  }
  
  
   ********************
   facebook onState:
  
   private void onSessionStateChange(Session session, SessionState state, Exception exception) {
          // Check if the user is authenticated and
          // a deep link needs to be handled.
          if (state.isOpened()) {
              MenuItem item = menu1.findItem(R.id.action_next);
              item.setVisible(true);
              viewPager.setVisibility(View.VISIBLE);
  
          } else if (state.isClosed()) {
  
              // Make the recipe list hidden
   //
  //              MenuItem item = menu.findItem(R.menu.main);
   //             item.setVisible(false);
  //              viewPager.setVisibility(View.INVISIBLE);
          }
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/eIotI.png" alt="enter image description here"></p>