0
我目前在Android應用程序中實現了ActionbarSherlock的4.2.0版本。 而我在使用SearchView小部件時遇到問題。ClassNotFoundException和ActionbarSherlock SearchView
我目前已經實現了這樣的小部件:
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.SearchView;
import com.actionbarsherlock.widget.SearchView.OnQueryTextListener;
public class MainActivity extends SherlockFragmentActivity
{
/*...*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
searchView.setQueryHint(getResources().getString(R.string.searchHint_Label));
searchView.setIconifiedByDefault(true);
searchView.setOnQueryTextListener(new OnQueryTextListener(){
@Override
public boolean onQueryTextSubmit(String query) {
// Do stuff
}
@Override
public boolean onQueryTextChange(String newText) {
// TODO Auto-generated method stub
return false;
}
});
menu.add("Search")
.setIcon(R.drawable.abs__ic_search)
.setActionView(searchView)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
return true;
}
}
現在,每當我開始調試應用程序我碰到下面的錯誤在搜索查看的構造函數:
01-01 11:46:40.365: E/dalvikvm(1385): Could not find class 'com.actionbarsherlock.widget.SearchView$11', referenced from method com.actionbarsherlock.widget.SearchView.<init>
Call Stack:
Thread [<1> main] (Suspended (exception ClassNotFoundException))
<VM does not provide monitor information>
PathClassLoader.findClass(String) line: 240
PathClassLoader(ClassLoader).loadClass(String, boolean) line: 551
PathClassLoader(ClassLoader).loadClass(String) line: 511
DexFile.defineClass(String, ClassLoader, int, ProtectionDomain) line: not available [native method]
DexFile.loadClassBinaryName(String, ClassLoader) line: 207
PathClassLoader.findClass(String) line: 200
PathClassLoader(ClassLoader).loadClass(String, boolean) line: 551
PathClassLoader(ClassLoader).loadClass(String) line: 511
MainActivity.onCreateOptionsMenu(Menu) line: 124
MainActivity(Watson).onCreatePanelMenu(int, Menu) line: 45
ActionBarSherlockCompat(ActionBarSherlock).callbackCreateOptionsMenu(Menu) line: 559
ActionBarSherlockCompat.preparePanel() line: 479
ActionBarSherlockCompat.dispatchInvalidateOptionsMenu() line: 272
ActionBarSherlockCompat$1.run() line: 984
ViewRoot(Handler).handleCallback(Message) line: 587
ViewRoot(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 130
ActivityThread.main(String[]) line: 3683
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 507
ZygoteInit$MethodAndArgsCaller.run() line: 839
ZygoteInit.main(String[]) line: 597
NativeStart.main(String[]) line: not available [native method]
內出現此錯誤我使用應用程序支持的所有Android版本(2.2 - 4.2) 在發生此異常之後恢復調試時,應用程序運行良好,SearchView也可以正常工作,但我仍然在想爲什麼發生此異常。
添加此代碼我試圖移動菜單定義XML如你所說,但事實並非如此解決例外。這個例外仍然發生在'inflater.inflate' –
那inflater.inflate中的實際問題是什麼? –
請檢查您的活動此導入com.actionbarsherlock.view.MenuInflater剩餘 –