I am trying to integrate simple map app with a place search functionality and I am facing the problem is that searching bar is not coming out in the map. I'm not sure what is the reason, as i'm beginner in android. however onCreateOptionsMenu
code is as follow, please any solution would be very thankful.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
// get a reference to the EditText widget for the search option
View searchRef = menu.findItem(R.id.action_search).getActionView();
mSearchEditText = (EditText) searchRef.findViewById(R.id.searchText);
// set key listener to start search if Enter key is pressed
mSearchEditText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
onSearchButtonClicked(mSearchEditText);
return true;
}
return false;
}
});
return true;
}
Error:
E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException at com.example.adrian.placesearch.MainActivity.onCreateOptionsMenu(MainActivity.java:106)