Android Development: Java.lang.IllegalStateException Error

Source: Internet
Author: User

It is common to change the UI when the ListView list refreshes data.

LOG:

The content of the adapter has changed but the ListView does not receive a notification. Make sure the content of your adapter are not modified from a background thread, but only from the UI thread.  

The log in the DDMS cannot be positioned to the exact error location. To check for errors, start with the following points:

1, check the thread, determine that there is no direct call adapter in background thread, if there is, please remove the relevant code to handler processing;
2, try to put the data in the adapter class management, do not need to clear the information (write clear ()), timely use notifydatasetchanged () refresh;
3, in the activity or fragment suitable position (Onpause/onstop) to check the thread in time, there is adapter data processing related should be stopped immediately;
4. This error often occurs after the activity is dormant, mainly by using adapter less carefully. If the reason is not found, stop all background thread in the OnPause () function and empty the data in adapter at the front of the Onresume () function, and adapter.notifydatasetchanged (). Then re-update the load data, which generally resolves the issue.  

The mistake I made was:

The adapter data is emptied adapter.getDateList.clear () in advance, and the adapter.notifydatasetchanged () is not called in time, Causes the ListView to throw java.lang.IllegalStateException this exception without data.

User experience: Refresh page or drop-down refresh, finger Click any UI, cause crashes.

Workaround: Write Adapter.getDateList.clear () and adapter.notifydatasetchanged () together

Android Development: Java.lang.IllegalStateException Error

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.