. lang。android.view ClassCastException。无法将$1转换为android.support.v7.widget.Toolbar$SavedState

时间:2023-01-21 00:28:22

My app gets crashed frequently when it goes from background to foreground. Scenerio: Suppose iam playing any games and my app is in recent list and after playing,if i selects app,it will crash and shows the error. There is no toolbar in my app,Only actionbar i used.

我的应用程序在从后台到前台的时候经常会崩溃。Scenerio:假设我正在玩游戏,我的应用程序在最近的列表中,如果我选择app,它会崩溃并显示错误。我的app中没有工具栏,只有我用过的actionbar。

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fcords.android/com.fcords.android.Home.HomeScreen.HomePage_New}: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.support.v7.widget.Toolbar$SavedState
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
        at android.app.ActivityThread.access$800(ActivityThread.java:148)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5312)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
 Caused by: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.support.v7.widget.Toolbar$SavedState
        at android.support.v7.widget.Toolbar.onRestoreInstanceState(Toolbar.java:1048)
        at android.view.View.dispatchRestoreInstanceState(View.java:13639)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2889)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2895)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2895)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2895)
        at android.view.View.restoreHierarchyState(View.java:13617)
        at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1982)
        at android.app.Activity.onRestoreInstanceState(Activity.java:1032)
        at android.app.Activity.performRestoreInstanceState(Activity.java:987)
        at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1184)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2287)

           

           

Anybody face this issue?Thanks in advance.

任何人面对这个问题?提前谢谢。

1 个解决方案

#1


13  

Problem Fixed in my case:

解决了我的问题:

Issue in my case is :

我的问题是:

1:I have an id in xml which have same name as a layout.

1:我有一个xml id,它的名称与布局相同。

ie:in my case ,i have a custom action bar layout named as "action_bar.xml" and an id in another layout as "+id/action_bar".So this cause problem when app is not in the memory and while recreating that page .

ie:在我的例子中,我有一个自定义的动作栏布局,名为“action_bar”。另一个布局中的id为“+id/action_bar”。所以当app不在内存中重新创建页面时就会出现问题。

NOTE:DONT USE SAME ID / LAYOUT NAMES multiple times.

注意:不要多次使用相同的ID /布局名。

#1


13  

Problem Fixed in my case:

解决了我的问题:

Issue in my case is :

我的问题是:

1:I have an id in xml which have same name as a layout.

1:我有一个xml id,它的名称与布局相同。

ie:in my case ,i have a custom action bar layout named as "action_bar.xml" and an id in another layout as "+id/action_bar".So this cause problem when app is not in the memory and while recreating that page .

ie:在我的例子中,我有一个自定义的动作栏布局,名为“action_bar”。另一个布局中的id为“+id/action_bar”。所以当app不在内存中重新创建页面时就会出现问题。

NOTE:DONT USE SAME ID / LAYOUT NAMES multiple times.

注意:不要多次使用相同的ID /布局名。