ClassCastException - android.support.v7.widget.Toolbar

时间:2015-04-19 19:58:41

标签: android android-appcompat classcastexception android-toolbar

更新了材料设计支持库后,我在某些设备(三星,Wiko)上崩溃了

java.lang.ClassCastException
com.wax.app.MainActivity.onOptionsItemSelected(MainActivity.java:310)
android.app.Activity.onMenuItemSelected(Activity.java:2612)
android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:350)
android.support.v7.app.ActionBarActivity.onMenuItemSelected(ActionBarActivity.java:152)
android.support.v7.app.ActionBarActivityDelegate$1.onMenuItemSelected(ActionBarActivityDelegate.java:75)
android.support.v7.widget.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:44)
android.support.v7.internal.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:76)
android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:164)
android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:738)
android.support.v7.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:802)
android.support.v7.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:153)
android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:949)
android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:939)
android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:596)
android.support.v7.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:145)
android.view.View.performClick(View.java:4439)
android.view.View$PerformClick.run(View.java:18395)
android.os.Handler.handleCallback(Handler.java:725)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:176)
android.app.ActivityThread.main(ActivityThread.java:5319)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
dalvik.system.NativeStart.main(Native Method)

我刚把它添加到Progruard

-keep class !android.support.v7.internal.view.menu.**,android.support.v7.** {*;}

我该怎么办?谢谢:)

编辑:这里是onOptionsItemSelected()方法,第310行介于“int id”和第一个if语句之间

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.close) {
        NewsContainer fr = (NewsContainer) getSupportFragmentManager().findFragmentById(R.id.container);
        fr.closePage();
        item.setVisible(false);
    }

    if (id == R.id.expand) {

        VisualizzabiliInApp fr1 = (VisualizzabiliInApp) getSupportFragmentManager().findFragmentById(R.id.container);
        fr1.expand();

        if (item.getTitle().equals("Mostra Filtri")) {
            item.setIcon(R.drawable.ic_expand_less_white_24dp);
            item.setTitle("Nascondi Filtri");
        } else {
            item.setIcon(R.drawable.ic_expand_more_white_24dp);
            item.setTitle("Mostra Filtri");
        }
    }
    return super.onOptionsItemSelected(item);
}

0 个答案:

没有答案