shreyaloclistfragment でリスト検索ビューを作成しようとしています。次の行で NullPointerException を取得しています
final SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
私の方法は
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater ) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate( R.menu.menu_search, menu);
System.out.println( "inflating menu");
final SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
showFilteredItems( newText );
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
return true;
}
};
searchView.setOnQueryTextListener(queryTextListener);
return;
}
スタックトレース
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.sears.syw.FragmentShopsTab.onCreateOptionsMenu(FragmentShopsTab.java:52)
at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:55)
at
com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:559 )
at
com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSh erlockNative.java:65)
at