我已经安装了支持库,以获得操作栏也是android的$工作p $ P API 11
i have installed the support library to get the action bar worked also in android pre API 11
当我启动应用程序时,logcat的给这个错误:
When i start the application, the logcat give 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 search around the web but i found nothing. Thank you
MainActivity.Java
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;
}
}
}
推荐答案
我觉得这是在支持库SearchView.java类的错误,你可以看到它是在一个共同的实现文件使用View.OnLayoutChangeListener:
I think this is a bug in SearchView.java class in support library, you can see that it is using View.OnLayoutChangeListener in a common implementation file:
https://android.googlesource.com/platform/frameworks/support.git/+/android-4.3_r1/v7/appcompat/src/android/support/v7/widget/SearchView.java
这使得类加载器来试装View.OnLayoutChangeListener这是因为提供API级别11 - 即使这* SDK11方法甚至没有叫。我想这个方法addOnLayoutChangeListenerToDropDownAnchorSDK11应该被移动到外部的Java类,并仅用于设备的API为> = 11。
this makes class loader to try loading View.OnLayoutChangeListener which is available since api level 11 - even if this *SDK11 method is not even called. I suppose this method addOnLayoutChangeListenerToDropDownAnchorSDK11 should be moved to external java class and used only if device API is >= 11.
您可以重现这个bug复制此code到自己的活动:
You can reproduce this bug copying this code to 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();
}
}
下面
是logcat的打印:
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
我不知道,如果这虫子居然引起任何问题,在我的情况下搜索查看适用于API级别10,也高于测试使我的活动工作。也许我失去了一些东西。
I am not sure if this bug Is actually causing any problems, in my case SearchView works on API Level 10, also above tests allow my activity to work. Maybe I am missing something here.
相关推荐
最新文章