Comment faire pour modifier l'ActionBar de l'élément de menu icône dynamiquement

Je veux changer l'icône d'option de menu dynamiquement que je reçois la notification à partir d'un serveur. Cependant, je suis un NullPointerException lorsque les codes pour modifier l'élément de menu de l'icône exécuter.

Codes que j'ai utilisé pour modifier l'élément de menu de l'icône sont définis dans le onCreatOptionsMenu méthode comme suit:

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
     //getMenuInflater().inflate(R.menu.main, menu);
     this.menu = menu;
     if (mDrawerLayout != null && isDrawerOpen())
         showGlobalContextActionBar();
         MenuInflater menuInflater = this.getMenuInflater();
         menuInflater.inflate(R.menu.notification, menu);
         return super.onCreateOptionsMenu(menu);
     }
 }

et dans le updateCount méthode, je suis l'évolution de l'icône comme suit:

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 > 0) {
               if(hot_count>0)
            {
                if (menu != null) {
                    MenuItem item = menu.findItem(R.id.menu_hotlist);
                    if (item != null) {
                        item.setIcon(R.drawable.ic_notification1);
                    }
                }
            }
            }                   
        }
    });
}

Voici mon menuitem "notification"fichier.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
   >

     <item android:id="@+id/menu_hotlist"
        android:actionLayout="@layout/action_bar_notification_icon"
        android:showAsAction="always"
        android:icon="@drawable/ic_notification"
        android:title="Notification" />

</menu>

Voici mon logcat:

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)

S'il vous plaît aider.

OriginalL'auteur ankur arora | 2015-01-20