Java.lang.IllegalArgumentException:Wrong State Class, expecting View state but received class Cn.etouch.ecalendar. Waterfallview. Staggeredgridview$gridlistsavedstate instead. This usually happens when the different type has the same ID in the same hierarchy. This view ' s ID is id/refresh_gridview. Make sure with the same ID.
as the log prompts, the ID is conflicting. But I looked at the XML layout file carefully, and there was no conflicting ID, and in fact, there are often duplicate IDs in the XML layout file. There are also some on the web saying that through the clean project, this will not solve the problem.
The situation I encountered was: Fragmenta includes FragmentA1,FragmentA2,Fragmenta3,fragementa3 has a custom GridView, and when switching between A1,A2 and A3, the program crashes , and reported the above errors.
ID The same? It may be the same ID. Because, when A1,A2 and A3 switch, the GridView state of A3 is saved, of course, the ID is saved. The next time you switch to A3, the same ID situation may occur. (I don't know what I understand, right?) )
This is the time to rewrite the onrestoreinstancestate function in the GridView:
Default:
@Override
protected void Onrestoreinstancestate (parcelable state) {
Super.onrestoreinstancestate (state); }
Modified to:
@Override
protected void Onrestoreinstancestate (parcelable state) {
try {
Super.onrestoreinstancestate (state);
}catch (Exception e) {}
State=null;
}
Run the program again and the problem is resolved
Java.lang.IllegalArgumentException:Wrong State Classs