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
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;
}
});
You need to ensure you add the Android Support Library correctly in Eclipse to remove the following error from the log 'Could not find class android.support.v7.widget.SearchView$5 referenced from method android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11'.
The key thing to remember, don't forget to uncheck Android Dependencies when adding the Support Library because the v7 appcompat library has resources. After making the change to your dependencies in your support library project, clean the support library project and that's it.
Refer to complete procedure in section Adding Libraries with Resources of official Google doco on how to add support libraries with resources.
Excerpt from above referenced doco in case link changes in future:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With