1

私は 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);
    }
}

うまく機能していますが、常にこの警告が表示され、考えさせられます...

手伝ってくれてありがとう!

4

1 に答える 1

-2

あなたはこのタイプのメニューを試してみてください

ファストフォール Actionbar libeler プロジェクトを追加し、extend SherlockFragmentActivity でアクティビティを呼び出します

public boolean onCreateOptionsMenu(Menu menu) {

        menu.add(0, menuHome, 1, getString(R.string.home))
                .setIcon(R.drawable.home)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        menu.add(0, menuAction, 1, getString(R.string.action))
                .setIcon(R.drawable.action)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        SubMenu subMenuAdd = menu.addSubMenu(0, menuAdd, 1,
                getString(R.string.add)).setIcon(R.drawable.add);
        subMenuAdd.add(0, menuAaddFence, 1, getString(R.string.add_fence));
        subMenuAdd.add(0, menuEditFence, 1, getString(R.string.edit_fence));
        subMenuAdd.add(0, menuDeleteFence, 1, getString(R.string.delete_fence));
        subMenuAdd.add(0, menuShowAllFence, 1, getString(R.string.show_all_fence));
        MenuItem menuItem = subMenuAdd.getItem();
        menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS
                | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        return super.onCreateOptionsMenu(menu);
    }

    /** Perform selected functionality in to the menu **/
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case menuHome:

            Intent refresh = new Intent(this, HomeActivity.class);
            startActivity(refresh);
            this.finish();

            break;

        case menuAction:
            intent = new Intent(HomeActivity.this, Actionactivity.class);
            startActivity(intent);
            break;

        case menuAaddFence:
            AddShowDialog();
            break;

        case menuDeleteFence:
            DeleteFenceDialog();

            break;

        case menuShowAllFence:
            intent = new Intent(HomeActivity.this, ShowAllFenceActivity.class);
            startActivity(intent);

            break;


        case menuEditFence:
            EditFenceDialog();
            break;

        default:
            break;
        }
        return super.onOptionsItemSelected(item);
    }
于 2012-04-25T11:16:07.087 に答える