Bottombar: `IllegalArgumentException: Wrong state class` when call `Activity.recreate()`

Created on 26 Aug 2016  路  13Comments  路  Source: roughike/BottomBar

Caused by: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.os.Bundle instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/bottomBarFlux. Make sure other views do not use the same id.
at android.view.View.onRestoreInstanceState(View.java:15659)
at com.roughike.bottombar.BottomBarTab.onRestoreInstanceState(BottomBarTab.java:453)

bug v2

Most helpful comment

@roughike any update? Do you need help on something?

All 13 comments

In BottomBarTab.java

@Override
    public void onRestoreInstanceState(Parcelable state) {
        if (badge != null && state instanceof Bundle) {
            Bundle bundle = (Bundle) state;
            badge.restoreState(bundle, indexInContainer);

            state = bundle.getParcelable("superstate");
        }
        super.onRestoreInstanceState(state);
    }

=> if (badge != null && state instanceof Bundle) will never be true (because view is re-create)
Must be if(state instanceof Bundle) and badge must be init in the if, no?

Can you provide more details how did you encounter this issue?

I will create a test application soon.

@roughike I made a test app project https://github.com/Kevinrob/bottom-bar-test
The APK for testing without build => https://github.com/Kevinrob/bottom-bar-test/raw/master/TestApp/app-debug.apk

_Just click first button and second_ => crash :bomb:

The problem is that when a view is restored, a new instance of the class is created... We have to re-create the badge object if needed. :smiley:

We are also running into this issue in a production app, Nearby Live.

This is now fixed and will be released in the v2.0.3 version during the weekend. This was due to the fact that the super.onRestoreInstanceState() method expects a View state (Parcelable), but received the Bundle we're storing our custom state data. The fix was to get that Parcelable out of the custom Bundle and pass that instead.

Huge thanks to @Kevinrob for reporting and helping to reproduce the issue!

Good news! Glad to read that. Thanks

@roughike Sorry for asking that, but what about the v2.0.3 release? :smile:
I'd love to use it instead of my temporary forked repository

@roughike, can you please release the version with this fix? My app is crashing :)

Would be great to have this fix in a new release soon!

@roughike any update? Do you need help on something?

@roughike Since its already fixed can we have a .release for this?

Thank you @roughike for publishing 2.1.0 with this fix! https://bintray.com/roughike/maven/bottom-bar/2.1.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rodrigobressan picture rodrigobressan  路  4Comments

zhangzhzh picture zhangzhzh  路  7Comments

LOG-TAG picture LOG-TAG  路  5Comments

giautm picture giautm  路  4Comments

LiuDeng picture LiuDeng  路  5Comments