0

I'm getting the following error,

 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setOnQueryTextListener(android.support.v7.widget.SearchView$OnQueryTextListener)' on a null object reference

on this code:

 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    inflater.inflate(R.menu.search_menu, menu);
    final MenuItem item = menu.findItem(R.id.search);

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
    searchView.setOnQueryTextListener(this);

}

I can't figure out how to fix it - does anyone have any suggestions? I understand what a nullpointer exception is, but I don't understand why searchView is null.

javapalava
  • 711
  • 1
  • 6
  • 15
  • this is saying that `searchView` is null. – Scary Wombat Aug 25 '16 at 02:42
  • Hi @ScaryWombat - I understand that. I know what a null pointer exception is, but I don't know why searchView is null. – javapalava Aug 25 '16 at 02:45
  • If problem persists after changing android:actionViewClass="android.support.v7.widget.SearchView" to app:actionViewClass="android.support.v7.widget.SearchView" and none of other solutions working then problem may be in your enabled proguard. so I use -keep class android.support.v7.widget.SearchView { *; } in my proguard-rules.pro file and its working perfectly. – WonderSoftwares Sep 03 '16 at 05:38

0 Answers0