Android, Logcat gives error about SearchView class

I installed a support library to make the action bar work in the Android API

When I run the application, the log code reports this error:

08-20 19:54:41.600: I/dalvikvm(9828): Failed resolving Landroid/support/v7/widget/SearchView$5; interface 809 'Landroid/view/View$OnLayoutChangeListener;' 08-20 19:54:41.600: W/dalvikvm(9828): Link of class 'Landroid/support/v7/widget/SearchView$5;' failed 08-20 19:54:41.600: E/dalvikvm(9828): Could not find class 'android.support.v7.widget.SearchView$5', referenced from method android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11 08-20 19:54:41.600: W/dalvikvm(9828): VFY: unable to resolve new-instance 734 (Landroid/support/v7/widget/SearchView$5;) in Landroid/support/v7/widget/SearchView; 08-20 19:54:41.600: D/dalvikvm(9828): VFY: replacing opcode 0x22 at 0x0002 08-20 19:54:41.600: D/dalvikvm(9828): VFY: dead code 0x0004-000a in Landroid/support/v7/widget/SearchView;.addOnLayoutChangeListenerToDropDownAnchorSDK11 ()V 

Can someone help me, I'm looking on the Internet, but did not find anything. thank you

MainActivity.Java

  package com.example.fanculo; import android.os.Bundle; import android.app.SearchManager; import android.content.Context; import android.support.v4.view.MenuItemCompat; import android.support.v7.widget.SearchView; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends ActionBarActivity{ ActionBar actionBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); actionBar = getSupportActionBar(); actionBar.setTitle("Test"); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); // Configure the search info and add any event listeners searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(true); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_search: onSearchRequested(); return true; default: return false; } } 

}

+4
source share
3 answers

I think this is an error in the SearchView.java class in the support library, you can see that it uses View.OnLayoutChangeListener in the general implementation file:

https://android.googlesource.com/platform/frameworks/support.git/+/android-4.3_r1/v7/appcompat/src/android/support/v7/widget/SearchView.java

this makes the classloader try loading the View.OnLayoutChangeListener, which is available from api level 11, even if this * SDK11 method is not even called. I believe that this addOnLayoutChangeListenerToDropDownAnchorSDK11 method should be moved to an external java class and only used if the device API is>> 11.

You can reproduce this error by copying this code into your own activity:

 private void addOnLayoutChangeListenerToDropDownAnchorSDK11() { new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { } }; } public void onCreate(...) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addOnLayoutChangeListenerToDropDownAnchorSDK11(); } } 

below is what logcat prints:

 08-31 22:50:33.030: INFO/dalvikvm(20753): Failed resolving Lcom/example/ActionBarTester/MyActivity$1; interface 813 'Landroid/view/View$OnLayoutChangeListener;' 08-31 22:50:33.030: WARN/dalvikvm(20753): Link of class 'Lcom/example/ActionBarTester/MyActivity$1;' failed 08-31 22:50:33.030: ERROR/dalvikvm(20753): Could not find class 'com.example.ActionBarTester.MyActivity$1', referenced from method com.example.ActionBarTester.MyActivity.addOnLayoutChangeListenerToDropDownAnchorSDK11 08-31 22:50:33.030: WARN/dalvikvm(20753): VFY: unable to resolve new-instance 903 (Lcom/example/ActionBarTester/MyActivity$1;) in Lcom/example/ActionBarTester/MyActivity; 08-31 22:50:33.030: DEBUG/dalvikvm(20753): VFY: replacing opcode 0x22 at 0x0000 08-31 22:50:33.030: DEBUG/dalvikvm(20753): VFY: dead code 0x0002-0005 in Lcom/example/ActionBarTester/MyActivity;.addOnLayoutChangeListenerToDropDownAnchorSDK11 ()V 

I'm not sure if this error actually causes any problems, in my case SearchView works at API level 10, and the tests above allow my activity to work. Maybe something is missing me.

+8
source

How about using ActionBarSherlock? It is flexible and supports older versions, and is also very easy to implement.

All you have to do is switch each class in which you extend the Activity in To SherlockActivity and also the fragment. I advise you to try! https://github.com/JakeWharton/ActionBarSherlock

0
source

You need to make sure that you have correctly added the Android V7 support library to Eclipse in order to remove the following error from the log 'Could not find android.support.v7.widget.SearchView $ 5 class referenced by android.support.v7.widget.SearchView method .addOnLayoutChangeListenerToDropDownAnchorSDK11.

The main thing to remember, do not forget to disable Android Dependencies when adding a support library, since the appcompat v7 library has resources. After making changes, depending on your support library project, clean up the support library project and it.

Refer to the complete procedure in the Adding Libraries with Resources section of the official Google Doco on how to add support libraries with resources.

An excerpt from the top of the doco link in case of future link changes:

  • Make sure you download the Android Support Library using the SDK Manager.
  • Create a library project and ensure the required JAR files are included in the project build path:
    • Choose File> Import.
    • Select an existing Android code in the workspace and click Next.
    • Go to the SDK installation directory and then to the library support service. For example, if you are adding an appcompat project, go to / extras / android / support / v 7 / appcompat /.
    • Click Finish to import the project. For the v7 appcompat project, you should now see a new project called android-support-v7-appcompat.
    • In the new library project, expand the libs / folder, right-click each .jar and choose Build Path> Add To Build Path. For example, when creating a v7 appcompat project, add the android-support-v4.jar and android-support-v7-appcompat.jar files for the build path.
    • Right-click the project and choose Build Path> Configure Build Path. On the Order and Export tab, check the .jar files that you just added to the build path, so they are available for projects that depend on this library project. For example, for the appcompat project, you need to export the android-support-v4.jar and android-support-v7-appcompat.jar files.
    • Uncheck the Android Dependencies box.
    • Click OK to complete the changes.
-one
source

Source: https://habr.com/ru/post/1498057/


All Articles