Could not find class 'android.support.v7.widget.SearchView$5'

android, android-logcat, java

Solution

There isn't a lot of code to go off of here, but I ran into this situation myself and here is what happened to me:

I was using the v7 compat library in order to have an ActionBar on Android 2 I am implementing the search interface stuff.

Basic Setup Code (in `onCreateOptionsMenu()`)

SearchManager searchManager =
        (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
SupportMenuItem searchMenuItem = ((SupportMenuItem) menu.findItem(R.id.menu_search));
SearchView searchView = (SearchView) searchMenuItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));

Bad Code

searchMenuItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
    @Override
    public boolean onMenuItemActionExpand(MenuItem item) {
        // on search expand stuff
        return true;
    }

    @Override
    public boolean onMenuItemActionCollapse(MenuItem item) {
        // on search collapse stuff
        return true;
    }
});

Unfortunately the problem here is that we are calling a method that is only supported in v14 so we get a "weird" run-time error when it tries to load some classes that are implicitly used. That's not a very good explanation, but basically it's the same reason we need to use `getSupportActionBar()` instead of `getActionBar()`.

Good Code

searchMenuItem.setSupportOnActionExpandListener(new MenuItemCompat.OnActionExpandListener() {
    @Override
    public boolean onMenuItemActionExpand(MenuItem item) {
        // do work
        return true;
    }

    @Override
    public boolean onMenuItemActionCollapse(MenuItem item) {
        // do work
        return true;
    }
});

Problem

I get this error in y Logcat. Does anyone know what it is? ``` 08-22 19:02:57.830: E/dalvikvm(660): Could not find class 'android.support.v7.widget.SearchView$5', referenced from method android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11 ```

Original source