java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.support.v7.widget.Toolbar$SavedState

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.

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.


Problem Fixed in my case:

Issue in my case is :

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

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 .

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

ClassCastException: android.view.AbsSavedState$1 cannot be cast , java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.Progress #2571 Closed jonathan-jd4software opened this issue May 1, 2018 · 15 comments


This can also happen in this edge case:

If you create a custom view programmatically inside the constructor of another parent view that has the AttributeSet parameter:

   public ToggleButtonDescriptive(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.toggleButton = new SquareToggleButton(ctx, attributeSet);
    }

DO NOT pass the AttributeSet to that child View:

toggleButton = new SquareToggleButton(ctx, attributeSet);

As passing the AttributeSet causes the child view to have the same id as the parent and thus Android tries to restore the parents SavedState to that child view or vice versa. Instead omit the AttributeSet parameter altogether, like this:

toggleButton = new SquareToggleButton(ctx);

AbsSavedState cannot be cast to HorizontalScrollView$SavedState , java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.Progres JonathanDibble GB Member April 2018 in Xamarin.Forms


In my case i have layout in my screen with ChipGroup and chips without id's. Then if I return to this screen from other's - I got this error "java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState". So just added id's to chip's and all works fine.

java+lang+ClassCastException+android+widget+LinearLayout+ , Join a community of over 2.6m developers to have your questions answered on java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to java.lang.Boolean of Xamarin Forms SideDrawer. New here? Start with our free trials.


Android java.lang.ClassCastException:android.view , java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to 하나의 xml에 같은 id가 중복으로 정의되어 있는 문제 문제가 발생한 View와 같은 id가 선언되어 있는지 체크해보면 된다.


java.lang.ClassCastException: android.view.AbsSavedState$1 , I'm trying to start a Fragment inside my RecycleAdapter but when cast my Context with the AppCompatActivity the App crashed and inside logcat I got the message that android.app.Application cannot be cast to android.support.v7.app.AppCompatActivity. here is my onClickListener inside RecycleAdapter. h


java.lang.RuntimeException: Caused by: java.lang ,