ClassNotFoundException when unmarshalling android.support.v7.widget.Toolbar$SavedState
Asked Answered
O

3

21

I am seeing the following error in my Android crash reports:

android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.v7.widget.Toolbar$SavedState
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
   at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3974)
   at android.app.ActivityThread.access$900(ActivityThread.java:139)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1299)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:149)
   at android.app.ActivityThread.main(ActivityThread.java:5257)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
   at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.v7.widget.Toolbar$SavedState
   at android.os.Parcel.readParcelableCreator(Parcel.java:2154)
   at android.os.Parcel.readParcelable(Parcel.java:2104)
   at android.os.Parcel.readValue(Parcel.java:2020)
   at android.os.Parcel.readSparseArrayInternal(Parcel.java:2382)
   at android.os.Parcel.readSparseArray(Parcel.java:1742)
   at android.os.Parcel.readValue(Parcel.java:2077)
   at android.os.Parcel.readArrayMapInternal(Parcel.java:2321)
   at android.os.Bundle.unparcel(Bundle.java:249)
   at android.os.Bundle.getSparseParcelableArray(Bundle.java:1273)
   at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1744)
   at android.app.Activity.onRestoreInstanceState(Activity.java:1017)
   at android.app.Activity.performRestoreInstanceState(Activity.java:989)
   at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1138)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2284)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
   at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3974)
   at android.app.ActivityThread.access$900(ActivityThread.java:139)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1299)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:149)
   at android.app.ActivityThread.main(ActivityThread.java:5257)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
   at dalvik.system.NativeStart.main(NativeStart.java)

It appears to happen intermittently when resuming an activity. I do not directly access the SavedState class in any code.

EDIT: Layout Xml for my activity is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">

<include layout="@layout/toolbar" />
....

And toolbar XML is

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

And in my Activity's onCreate I do

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_show_txn);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    localBroadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
    mResources = getResources();

    if (savedInstanceState != null) {
        long id = savedInstanceState.getLong(STA_TXN_ID);
        ...
    } else {
        ... read fresh
    }

    mDateTV = (TextView) findViewById(R.id.ASTVDate);
    mDayTV = (TextView) findViewById(R.id.ASTVDay);
    mCatName = (TextView) findViewById(R.id.ASTVCatName);
    mMonthTV = (TextView) findViewById(R.id.ASTVMonth);
    ....

    Calendar c = java.util.Calendar.getInstance();
    c.setTime(txn.getTxnDate());
    mDateTV.setText("" + c.get(Calendar.DAY_OF_MONTH));
    mDayTV.setText(c.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.US));
    mMonthTV.setText(c.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.US));
}

And I have been using appcompat-v7:22.1.1 and yes I get these errors after proguard.

Originative answered 4/5, 2015 at 11:11 Comment(9)
Post your xml and java code plsTracey
Added my relevant test code in edited quetionOriginative
Pls add the full java code, the problem is there according to log fileTracey
What version of appcompat-v7 are you using ?Dallis
Is this after proguard?Salto
Added the appcompat version and yes this is port proguardOriginative
Please add your comments to this bug code.google.com/p/android/issues/detail?id=175140Denver
I do not use proguard, but have this issue. Also I use toolbar with SupportMapFragment and appcompat-v7:22.2.0. I restore my app from background and get this error in fragment onCreate in super.onCreate() call.Clef
I am also having this problem. Did you ever find a solution?Apulia
M
3

Looks like following issue is exactly about it: https://code.google.com/p/android/issues/detail?id=196430

Moreen answered 22/5, 2016 at 16:49 Comment(2)
As a summary of the above Google Code issue, the problem seems to happen only on older devices (i.e. 2.3.7 and lower). Personally I ran into this issue with a device running API 10 (2.3.7). It looks like it will not be fixed any time soon, if ever, for older devices, but has been fixed on newer devices, so nothing users (and developers) can do short of getting a newer device.Glutamate
This is not only an older device problem. Its a restore state problem. If you take a newer phone, go into debug settings and force activities to always be killed you will see this happen. Which means if your newer phone is running low on memory and needs to kill off activities and then restore them from state it will fail. Google needs to fix this!Deese
A
1

According to AAverin's source, Google Issue 196430, build tools version 24 includes a fix.

E.G. change the build tools version in build.gradle:

buildToolsVersion "24.0.0"

Alternatively, prevent crashes by catching (in my particular case):

try {
    // Temporary fix for crash issue
    mapView.onCreate(savedInstanceState);
} catch (Throwable t) {
    t.printStackTrace();
}
Anemometry answered 8/9, 2016 at 19:17 Comment(2)
also in my case, it is crashing in mapview.oncreate(savedInstanceState) which is called in my fragment's onViewCreated() which is in a viewpagerTolle
And build tools 25 breaks it again!Used
B
0

I faced this problem when I was passing 2 parable objects one of type A and other of type B containing type A object. I passed them in parceable array and my problem got resolved.

Blakeslee answered 19/7, 2018 at 14:16 Comment(1)
Activity 1 Intent intent = new Intent(this, R1.class); Parcelable pa[] = null;<br/> pa = new Parcelable[3]; pa[0] = obj1; pa[1] = obj2; pa[2] = obj3; intent.putExtra(“ArrayObj”, pa); Activity 2 Parcelable ArrayObj[] = intent.getParcelableArrayExtra(“ArrayObj”); s1 = (T1)ArrayObj[0]; s2 = (T2)ArrayObj[1];;Blakeslee

© 2022 - 2024 — McMap. All rights reserved.