Java.lang.IllegalArgumentException:Wrong State Classs

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.