title: How to change the ActionBar menu item's icon dynamically
body: <p>I want to change the menu item's icon dynamically as I get notification from a server. However, I'm getting a <code>NullPointerException</code> when the codes to change the menu item's icon run.</p>
  
  <p>Codes I used to change the menu item's icon are defined in the <code>onCreatOptionsMenu</code> method as follow:</p>
  
  <pre><code> @Override
   public boolean onCreateOptionsMenu(Menu menu) {
       // getMenuInflater().inflate(R.menu.main, menu);
       this.menu = menu;
       if (mDrawerLayout != null &amp;&amp; isDrawerOpen())
           showGlobalContextActionBar();
           MenuInflater menuInflater = this.getMenuInflater();
           menuInflater.inflate(R.menu.notification, menu);
           return super.onCreateOptionsMenu(menu);
       }
   }
  </code></pre>
  
  <p>and in the <code>updateCount</code> method, I am changing the icon as follow:</p>
  
  <pre><code>public void updateCount(int count) { 
      hot_count = count;
      System.out.println("Value of count: " + count);
      runOnUiThread(new Runnable() {
          @Override
          public void run() {
              // TODO Auto-generated method stub
              if (hot_count &gt; 0) {
                  if(hot_count&gt;0)
                      {
                      if (menu != null) {
                          MenuItem item = menu.findItem(R.id.menu_hotlist);
                          if (item != null) {
                              item.setIcon(R.drawable.ic_notification1);
                          }
                      }
                  }
              }                   
          }
      });
  }
  </code></pre>
  
  <p>Here is my menuitem "notification" file:</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
     &gt;
  
       &lt;item android:id="@+id/menu_hotlist"
          android:actionLayout="@layout/action_bar_notification_icon"
          android:showAsAction="always"
          android:icon="@drawable/ic_notification"
          android:title="Notification" /&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <p>Here's my logcat:</p>
  
  <pre><code>01-20 15:03:29.811: E/AndroidRuntime(10318): java.lang.NullPointerException
  01-20 15:03:29.811: E/AndroidRuntime(10318):    at com.xsinfosol.helpdesk_customer.TAB_Activity$3.run(TAB_Activity.java:294)
  01-20 15:03:29.811: E/AndroidRuntime(10318):    at android.os.Handler.handleCallback(Handler.java:730)
  01-20 15:03:29.811: E/AndroidRuntime(10318):    at android.os.Handler.dispatchMessage(Handler.java:92)
  01-20 15:03:29.811: E/AndroidRuntime(10318):    at android.os.Looper.loop(Looper.java:137)
  01-20 15:03:29.811: E/AndroidRuntime(10318):    at android.os.HandlerThread.run(HandlerThread.java:61)
  01-20 15:04:04.881: I/System.out(11629)
  </code></pre>
  
  <p>Please help.</p>