Unexplainable ClassCastException in android.widget.ProgressBar.onRestoreInstanceState

I've seen similar issues to this before, and it's because you have two id's that share the same name.

The onRestoreInstanceState has performed the findViewById method and the first view to be found was not the ProgressView.

Double check that your application does not reuse the same ID in two different places


I had a different issue: In one layout the root was a ScrollView while in the other the root was a RelativeView that contained the ScrollView. All widgets ids were identical and there were no duplicates. On rotate the crash log was:

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

Once I matched the layouts (so in both the root was either the RelativeLayout or ScrollView), the rotation worked fine.

Not sure why this would cause a crash so any insights would be appreciated...


In my case my portrait xml has Relativelayout and ScrollView from landscape xml with the same ID.

On my activity class I try to inflate the layout and assign it on ViewGroup

So when screen rotation occur it throws: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.ScrollView$SavedState

It's because the ScrollView extends FrameLayout while Relativelayout extends ViewGroup

So i just wrap the landscape xml with Relativelayout and solves the problem