Q:

Adding listener to ActionBar item, onOptionsItemSelected NullPointerException

*Answered!: * It turns out that you need to have title for an item even if you have an icon for it.
I am currently implementing (Sherlock)Action Bar in my application. I currently have an on screen button that refreshes my screen view and I want to move this button to be an item in my  action bar. Log of onOptionsItemSelected is not showing up in LogCat but Created menu is showing up. 
I do not know why I am getting a null pointer and can't find in the error log where the null is happening. The app only crashes when I click on the refresh button in the action bar and does everything else fine until that point.
public boolean onCreateOptionsMenu(Menu menu) {
        Log.i("Created Menu", "Yes");
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.main, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        Log.i("Got into onOptionsItemSelected", "Yes");
        switch(item.getItemId()){

        case R.id.action_refresh:

                new getFleetList().execute(getFleetListURL);
                progressBar.setVisibility(ProgressBar.VISIBLE);

        return true;

    }

StackTrace: 
07-09 12:52:27.594: W/dalvikvm(23570): threadid=1: thread exiting with uncaught exception (group=0x4132e930)
07-09 12:52:27.601: E/AndroidRuntime(23570): FATAL EXCEPTION: main
07-09 12:52:27.601: E/AndroidRuntime(23570): java.lang.NullPointerException
07-09 12:52:27.601: E/AndroidRuntime(23570):    at com.android.internal.view.menu.MenuItemImpl.toString(MenuItemImpl.java:496)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at java.lang.StringBuilder.append(StringBuilder.java:202)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at com.actionbarsherlock.app.SherlockFragmentActivity.onMenuItemSelected(SherlockFragmentActivity.java:201)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:547)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:115)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at android.view.View.performClick(View.java:4204)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at android.view.View$PerformClick.run(View.java:17355)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at android.os.Handler.handleCallback(Handler.java:725)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at android.os.Looper.loop(Looper.java:137)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at android.app.ActivityThread.main(ActivityThread.java:5041)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at java.lang.reflect.Method.invokeNative(Native Method)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at java.lang.reflect.Method.invoke(Method.java:511)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-09 12:52:27.601: E/AndroidRuntime(23570):    at dalvik.system.NativeStart.main(Native Method)

Edit, XML File:
Menu XML: 
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

     <item
        android:id="@+id/action_refresh"
        android:icon="@drawable/ic_action_refresh"
        android:orderInCategory="1"
        android:showAsAction="always"

        />

</menu>

A:

Are you using these imports
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

otherwise you will get error.
try this
@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {

    com.actionbarsherlock.view.MenuInflater inflate = getSupportMenuInflater();
    inflate.inflate(R.menu.main, menu);

    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.action_refresh:
            //do whatever you want
        break;
        default:
            return super.onOptionsItemSelected(item);
    }
}

****UPDATE****
<item
        android:id="@+id/action_legalnotice"
        android:orderInCategory="100"
        android:title="Legal Notices"/>
     <item
        android:id="@+id/action_refresh"
        android:icon="@drawable/ic_action_refresh"
        android:orderInCategory="1"
        android:showAsAction="always"

android:title="Your title here please"

        />

see this link for details: Null pointer exception showing in action bar sherlock library

