title: menu.findItem(R.id.*) is null- Android
body: <p>I am trying to enable/disable a refresh button when certain things happen in my app, but I get a null pointer exception that I can't figure out. I am setting a boolean <code>addingRefresh</code> or <code>removingRefresh</code> to true depending on the situation and then calling <code>invalidateOptionsMenu()</code> to enable or disable the button, however the menu item is returned null. I have searched the internet for why this may be but can't find anything.</p>
  
  <p>Code for <code>onCreateOptionsMenu()</code> (called when invalidateOptionsMenu() is called)</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      if (addingRefresh) {
          //below line as well as other similar line cause exceptions
          menu.findItem(R.id.action_refresh).setEnabled(true);
          addingRefresh = false;
      } else if (removingRefresh) {
          menu.findItem(R.id.action_refresh).setEnabled(false);
          removingRefresh = false;
      } else if (addingLoading) {
  
      }
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.main_activity_actions, menu);
      return super.onCreateOptionsMenu(menu);
  }
  </code></pre>
  
  <p>Thanks for any help!</p>