java.lang.IllegalArgumentException: Wrong state classs
java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class cn.etouch.ecalendar.waterfallview.StaggeredGridView$GridListSavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/refresh_gridView. Make sure other views do not use the same id.
按照Log的提示,是id起了衝突。但是我經過仔細檢視XML佈局檔案,並沒有起衝突的ID,事實上,在xml佈局檔案中經常有重名的id。網上還有一些說通過clean專案,這個也解決不了問題。
我遇到的情形是:FragmentA 中包括FragmentA1,FragmentA2,FragmentA3,FragementA3中有一個自定義的GridView,當A1,A2和A3之間切換時,程式就會崩潰,並報上述的錯誤。
id相同?確實可能是ID相同。因為,當A1,A2和A3切換的時候,將A3的gridView狀態儲存了,當然id也儲存下來了。下次再切換到A3就可能出現id相同的情形。(不知道理解的對不對?)
這時候需要重寫GridView中的onRestoreInstanceState函式:
預設:
@Override
protected void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(state); }
修改為:
@Override
protected void onRestoreInstanceState(Parcelable state) {
try {
super.onRestoreInstanceState(state);
}catch (Exception e) {}
state=null;
}
再次執行程式,問題得到解決
相關文章
- What is wrong?
- SQL can execute in wrong SchemaSQL
- Vuex之stateVue
- Working with State
- java.lang.IllegalArgumentException at java.sql.Date.getHoursJavaExceptionSQL
- Caused by: java.lang.IllegalArgumentException: port out of range:-1JavaException
- BottomSheetBehavior之java.lang.IllegalArgumentException:TheviewisnotassociatedwithBottomSheetBehaviorJavaExceptionView
- java.lang.IllegalArgumentException: Path index does not start with a "/" charactJavaExceptionIndex
- ReactState(狀態):React通過this.state來訪問state,通過this.setState()方法來更新stateReact
- 解決:java.lang.IllegalArgumentException: String must not be emptyJavaException
- Bug:java.lang.IllegalArgumentException: unknown document format for file:JavaExceptionORM
- 元件、Prop 和 State元件
- react 之 state 物件React物件
- 狀態模式(State)模式
- State Server 設定Server
- mysql show processlist stateMySql
- Monitoring WebSite StateWeb
- Simple state transition 3
- demoValue: state => state.demoValue是什麼語法呢?
- Connection to x as user y failed: ERROR: Wrong password for userAIError
- Caused by: java.lang.IllegalArgumentException: Unable to instantiate SparkSession with Hive supportJavaExceptionSparkSessionHive
- [譯] 元件、Prop 和 State元件
- DRIVER_POWER_STATE_FAILUREAI
- React 手稿 – Component stateReact
- Vuex之state和gettersVue
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- 狀態模式(State pattern)模式
- 設計模式之State設計模式
- Flutter State 深入理解Flutter
- Session State and Referenced Packages (246)SessionPackage
- swiftUI-@State 的作用SwiftUI
- torch.save(),torch.load(),state_dict(),load_state_dict()
- 【Oracle】Oracle wrong result一則(優化器問題)Oracle優化
- java.lang.IllegalArgumentException: Could not find class異常解決方式JavaException
- java.lang.IllegalArgumentException: Mapped Statements collection does not contain value forJavaExceptionAPPAI
- Widget 中的 State 解析
- Flutter Widget中的StateFlutter
- 說說React元件的StateReact元件