Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AndroidDeveloperLB opened this issue Mar 24, 2025 · 0 comments

Comments

@AndroidDeveloperLB
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants