Skip to content

[MaterialButton] Bug: "IllegalArgumentException: Wrong state class, expecting View State..." #4703

Open
@AndroidDeveloperLB

Description

@AndroidDeveloperLB

Description: Full description of issue here
I have some buttons in a Fragment, which is inside a settings screen.
Upon orientation change, for some reason, there is this crash with this exception in it:

java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class com.google.android.material.button.MaterialButton$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/fragment_ad__noAdsAlternativeBannerButton. Make sure other views do not use the same id.

Thing is, this ID exists only in this layout, used only by this Fragment.
Not only that, but changing something that's not related at all to this (such as the Admob app-id) could make the crash disappear.

Expected behavior: Screenshots and/or description of expected behavior
Shouldn't crash, and the workaround shouldn't exist as just changing/removing files that have nothing to do with it.

Source code: The code snippet which is causing this issue
Sadly it's a lot of code, and it's my app, so I can't publish it here.
I've published it on the issue tracker, but for some reason it got closed very soon after I've provided all the needed information and files:

https://issuetracker.google.com/issues/406012422

Minimal sample app repro: Please consider attaching a minimal sample app that reproduces the issue.
See above

Android API version: Android API version here
Occurs on Android API 35 (Android 15) .

Material Library version: Material Android Library version you are using here (e.g., 1.1.0-alpha07)

implementation("com.google.android.material:material:1.13.0-alpha12")

and also:

implementation("com.google.android.material:material:1.13.0-alpha11")

Device: Device on which the bug was encountered here
Both Pixel 6 and emulator

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions