material-components / material-components/material-components-android
[MaterialButton] Bug: "IllegalArgumentException: Wrong state class, expecting View State..."
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file, test, or minimal reproduction is provided in the issue. Start with the linked Google issue and reproduce the orientation-change crash on Android API 35 using Material Components 1.13.0-alpha11 or alpha12; done means the reported MaterialButton state-restoration failure is reproducible and its cause and fix are verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100