Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
<HorizontalScrollView
android:id="@+id/topics_scroll_view"
android:layout_width="match_parent"
android:layout_height="92dp"/>
<HorizontalScrollView
android:id="@+id/topics_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
i started getting this crash
Caused by java.lang.ClassCastException
android.view.AbsSavedState$1 cannot be cast to android.widget.HorizontalScrollView$SavedState
android.widget.HorizontalScrollView.onRestoreInstanceState (HorizontalScrollView.java:1678)
the crash is happening on this method in HorizontalScrollView
@Override
protected void onRestoreInstanceState(Parcelable state) {
if (mContext.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
// Some old apps reused IDs in ways they shouldn't have.
// Don't break them, but they don't get scroll state restoration.
super.onRestoreInstanceState(state);
return;
SavedState ss = (SavedState) state; //*******this line is crashing
super.onRestoreInstanceState(ss.getSuperState());
mSavedState = ss;
requestLayout();
i found a similar issue and i suspected that obfuscation is not keeping Parcelable and they suggested to add this to proguard file
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
when i looked at my proguard file i found that i have already included the below
-keepnames class * implements android.os.Parcelable { *; }
-keepclassmembers class * implements android.os.Parcelable { *; }
can anyone distinguish the problem and why it started crashing now when i changed the android:layout_height
?
does this make sense to anyone?
thanks in advance
EDIT: after reading some similar problems i found this one java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.support.v7.widget.Toolbar$SavedState
now if you read the answer its saying that using same android:id
for different view can cause this so it got my attention that i recently added a view that is included in the same layout with the HorizontalScrollView and that views hold this
<RelativeLayout
android:id="@+id/topics_scroll_view"
android:layout_width="match_parent"
android:layout_height="92dp"/>
Can this be the problem?
–
–
–
Yes absolutely this is because you are using same id for two layouts.
First, Cross check that your application is not reusing the same ID's in two different places.
The onRestoreInstanceState
has performed the findViewById
method and the first view to be found was not the HorizontalScrollView.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.