I want to implement the search view widget of Sherlock action bar. My problem is OnOptionItemSelected
of search view item. I am getting a null pointer exception in library activity.
The menu xml:
<item android:id="@+id/menu_search"
android:actionViewClass="com.actionbarsherlock.widget.SearchView"
android:icon="@android:drawable/ic_menu_search"
/>
Code snippet for option menu:
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.tvguide_menu, menu);
MenuItem mSearch = menu.findItem(R.id.menu_search);
searchView = new SearchView(getSupportActionBar().getThemedContext());
searchView.setQueryHint("Search for countries…");
searchView.setOnQueryTextListener(this);
mSearch.setActionView(searchView);
mSearch.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
}
I am getting a forced close on clicking over search android. I have shared my log below
04-17 15:10:08.508: E/AndroidRuntime(23283): FATAL EXCEPTION: main
04-17 15:10:08.508: E/AndroidRuntime(23283): java.lang.NullPointerException
04-17 15:10:08.508: E/AndroidRuntime(23283): at com.android.internal.view.menu.MenuItemImpl.toString(MenuItemImpl.java:490)
04-17 15:10:08.508: E/AndroidRuntime(23283): at java.lang.StringBuilder.append(StringBuilder.java:202)
04-17 15:10:08.508: E/AndroidRuntime(23283): at com.actionbarsherlock.app.SherlockFragmentActivity.onMenuItemSelected(SherlockFragmentActivity.java:201)
04-17 15:10:08.508: E/AndroidRuntime(23283): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:953)
04-17 15:10:08.508: E/AndroidRuntime(23283): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
04-17 15:10:08.508: E/AndroidRuntime(23283): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
04-17 15:10:08.508: E/AndroidRuntime(23283): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
04-17 15:10:08.508: E/AndroidRuntime(23283): at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:491)
04-17 15:10:08.508: E/AndroidRuntime(23283): at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:110)
04-17 15:10:08.508: E/AndroidRuntime(23283): at android.view.View.performClick(View.java:3511)
04-17 15:10:08.508: E/AndroidRuntime(23283): at android.view.View$PerformClick.run(View.java:14105)
04-17 15:10:08.508: E/AndroidRuntime(23283): at android.os.Handler.handleCallback(Handler.java:605)
04-17 15:10:08.508: E/AndroidRuntime(23283): at android.os.Handler.dispatchMessage(Handler.java:92)
04-17 15:10:08.508: E/AndroidRuntime(23283): at android.os.Looper.loop(Looper.java:137)
04-17 15:10:08.508: E/AndroidRuntime(23283): at android.app.ActivityThread.main(ActivityThread.java:4438)
04-17 15:10:08.508: E/AndroidRuntime(23283): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 15:10:08.508: E/AndroidRuntime(23283): at java.lang.reflect.Method.invoke(Method.java:511)
04-17 15:10:08.508: E/AndroidRuntime(23283): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-17 15:10:08.508: E/AndroidRuntime(23283): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-17 15:10:08.508: E/AndroidRuntime(23283): at dalvik.system.NativeStart.main(Native Method)