android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState

I am seeing the following error on Crashlytics with a lot of incidences:

Caused by java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
       at android.widget.CompoundButton.onRestoreInstanceState(CompoundButton.java)
       at android.view.View.dispatchRestoreInstanceState(View.java)
       at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
       at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
       at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
       at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
       at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
       at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java)
       at android.view.View.restoreHierarchyState(View.java)
       at android.support.v4.app.Fragment.restoreViewState(Fragment.java:494)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1486)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
       at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
       at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
       at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2466)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
       at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
       at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
       at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
       at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:620)
       at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java)
       at android.app.Activity.performStart(Activity.java)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
       at android.app.ActivityThread.access$900(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
       at android.os.Handler.dispatchMessage(Handler.java)
       at android.os.Looper.loop(Looper.java)
       at android.app.ActivityThread.main(ActivityThread.java)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)

However this stack trace says nothing about my codebase, since the exception is thrown at the platform level.

From what I read this might have to do with duplicate ids, but I cant find any in my code, any ideas on how to debug this?

I also tried to enable "Dont keep activities" on Developer options to force an instance restoration but I am unable to reproduce the crash manually.

This is little difficult to get exact issue without seeing code and exact activity/fragment class but There might be below reason which can help you to debug more..

  1. You might have duplicate name of your id or View which matching and creating memory leak when you are transforming.

  2. There might be wrong import of CompoundButton, might be you are using custom view or version impact.

java.lang.ClassCastException: android.view.AbsSavedState$1 , ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.​widget. CompoundButton$SavedState cannot be cast to android.widget. I keep getting this when I use the ObservableListView and rotate Caused by: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to com.github.ksoichiro.android.observablescrol

Well turns out I am using the new Chip component (extending CompoundButton), and had one group with a chip without an id.

And this somehow causes the app to crash on older phones (Android 6) because of the same id being assigned to multiple chips I can only guess.

I removed that Chip (which was not necessary anyway) and it does not crash anymore.

java.lang.ClassCastException: android.view , ClassCastException: android.view.AbsSavedState$1 cannot be cast to java.lang. at com.telerik.android.primitives.widget.sidedrawer. android, AbsSavedState cannot be cast to SavedState. As the title says, I usually use this blog to put down what's currently going on in my life.

this can be caused by a view with the same resId, as the containing layout's name (main cause).

it could also be caused from view with duplicate resIds, but that's less likely the cause.

reviewing all the fragment's XML suggested (difficult to tell which one causes that).

but Edit > Find > Find in Path ...makes it easy to search for occurrences;

to search for one layout's name after the other; then to search for view's resId.

Android : AbsSavedState cannot be cast to <View>$SavedState, AbsSavedState$1 cannot be cast to android.widget.CompoundButton$​SavedState at android.app. AbsSavedState$1@e738983, 3=android.view.​AbsSavedState$1@e738983 SavedState{8f32832 checked=true}, 27=android.​view. AbsSavedState$1 cannot be cast to XXX 08-05 207 Android ContextThemeWrapper cannot be cast to android .app.Activity

Android Orientation Change Crash, android.view.AbsSavedState$1 cannot be cast to android.widget.​CompoundButton$SavedState. I am seeing the following error on Crashlytics  cannot be cast to cannot be cast to ja java.sql.Timestamp cannot be cast to java.sql.Date cannot be applied to cannot be cannot-be Cannot cast from Vie node to traverse cannot be null Button cannot be resolved to a type HttpServletRequest cannot be resolved to a type R.layout.main cannot be resolved cannot be opened because the project file cannot be parsed. cannot be opened because the project file cannot be parsed. cannot be opened because the project file cannot be parsed. cannot connect

Android java.lang.ClassCastException:android.view , 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.

Comments
  • There is an activity which in onStart restores a fragment. Do You have any fragment containing RadioButton, Checkbox,Switch,ToggleButton? If so, try to put breakpoints there and check in Watches window if You are not casting them wrong.
  • Does your project have any custom View subclasses that derive from CompoundButton (or one of its subclasses)?
  • If possible try to get the same device on which your issue was reproduced and try switching application in various moments when your app is in front (especially on views which use fragments with CompoundButton) and then switch back to your app. It looks like the issue is happening when restoring views from saved state, however reproduction may be device specific.
  • It's possible this is happening due to structural changes in the layout between landscape and portrait modes.