我正在使用 ActionBarSherlock,我希望每次单击项目时都重建 ActionBar。对于那个我使用
supportInvalidateOptionsMenu();
每次调用它时,我都会收到警告(用 MenuInflater 标记)
Cannot instantiate class: @16974108
java.lang.ClassNotFoundException: @16974108 in loader dalvik.system.PathClassLoader[/data/app/de.abc.android.reader-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251)
at java.lang.ClassLoader.loadClass(ClassLoader.java:540)
at java.lang.ClassLoader.loadClass(ClassLoader.java:500)
at com.actionbarsherlock.view.MenuInflater$MenuState.newInstance(MenuInflater.java:463)
at com.actionbarsherlock.view.MenuInflater$MenuState.readItem(MenuInflater.java:366)
at com.actionbarsherlock.view.MenuInflater.parseMenu(MenuInflater.java:147)
at com.actionbarsherlock.view.MenuInflater.inflate(MenuInflater.java:97)
at de.abc.android.reader.ui.PaperPlayer.onCreateOptionsMenu(PaperPlayer.java:102)
at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:231)
at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:543)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.preparePanel(ActionBarSherlockCompat.java:463)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.dispatchInvalidateOptionsMenu(ActionBarSherlockCompat.java:269)
at com.actionbarsherlock.app.SherlockFragmentActivity.invalidateOptionsMenu(SherlockFragmentActivity.java:138)
at com.actionbarsherlock.app.SherlockFragmentActivity.supportInvalidateOptionsMenu(SherlockFragmentActivity.java:144)
at de.abc.android.reader.ui.PaperPlayer.setFontSizeUp(PaperPlayer.java:251)
at de.abc.android.reader.ui.PaperPlayer.onOptionsItemSelected(PaperPlayer.java:118)
at com.actionbarsherlock.app.SherlockFragmentActivity.onMenuItemSelected(SherlockFragmentActivity.java:279)
at com.actionbarsherlock.ActionBarSherlock.callbackOptionsItemSelected(ActionBarSherlock.java:587)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.onMenuItemSelected(ActionBarSherlockCompat.java:513)
at com.actionbarsherlock.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:738)
at com.actionbarsherlock.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:148)
at com.actionbarsherlock.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:879)
at com.actionbarsherlock.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:510)
at com.actionbarsherlock.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:145)
at android.view.View.performClick(View.java:3110)
at android.view.View$PerformClick.run(View.java:11934)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4135)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
这里是构建 ActionBar 的方法:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.paperplayer, menu);
if (isBiggestFontsize(getCurrentFontsize())) menu.findItem(R.id.ic_action_textup).setEnabled(false);
if (isSmallestFontsize(getCurrentFontsize())) menu.findItem(R.id.ic_action_textdown).setEnabled(false);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
Intent intent = new Intent(this, Library.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
case R.id.ic_action_textup:
setFontSizeUp();
return true;
case R.id.ic_action_textdown:
setFontSizeDown();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
它运作良好,但我总是收到这个警告,这让我思考......
感谢帮助!