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

3

8

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
Galloromance answered 22/8, 2013 at 17:6 Comment(13)
it can not find that class. Do you have that library in your libs folder ?Eggshell
Did you add the support library v7?Vue
Yes, i have the SearchView class in the library, i have import the android-support-v7-appcompat library to add the actionbare pre API 11Galloromance
Yes, but i don't understand why i get this errorGalloromance
i added the android-support-v7-appcompat libraryGalloromance
did you clean your project ??Eggshell
Maybe if you are using the action bar does not work in less than API 11.Vue
Isn't ActionBarSherlock recommended ?Eggshell
i add the support library v7 for include the actionbar in the devices pre API 11.Galloromance
I would like to try to fix this error before give up and use ActionBarSherlockGalloromance
Is the only solution. SorryVue
Thanks anyway, but this is so strangeGalloromance
could you please add some more infos about how you defined the menu and used it in the activity? i think i know wich is the problem but it's difficult to be sure about it without any codeDepressomotor
W
11

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;
    }
});
Walkling answered 3/9, 2013 at 19:36 Comment(1)
On thing I should mention, I am using Android Studio (and IntelliJ) and it gives me compile errors on this... but it works and runs and is just fine... I have filed a bug with AndroidStudio: code.google.com/p/android/issues/…Walkling
F
5

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:

  1. Make sure you have downloaded the Android Support Library using the SDK Manager.
  2. Create a library project and ensure the required JAR files are included in the project's build path:
    • Select File > Import.
    • Select Existing Android Code Into Workspace and click Next.
    • Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompat project, browse to /extras/android/support/v7/appcompat/.
    • Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
    • In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.
    • Right-click the project and select Build Path > Configure Build Path. In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
    • Uncheck Android Dependencies.
    • Click OK to complete the changes.
Felishafelita answered 5/9, 2013 at 8:5 Comment(0)
R
0

You need to add missing Support Library to the Project. In Eclipse: Right click at Project

Select Android Tools/Add Support Library...

Rationality answered 19/12, 2013 at 8:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.