ListView encounters a Problem Java.lang.IndexOutOfBoundsException:Invalid index 0, size is 0

Source: Internet
Author: User

Development encountered Java.lang.IndexOutOfBoundsException:Invalid index 0, size is 0

This anomaly sometimes happens, sometimes it's not very good to capture

Guess has given the data to list, and then let the main thread to display, and then continue to retrieve data in the background. It might be possible that the main thread is still not refreshed, and the backstage is giving the new data back.

So guessing is the problem of refreshing the head.

That is

The problems that arise here

So adjust to:

News.clear (); News.addall (LocalNews);
Newsadapter=new Newslistadapter (activity, News); Mnews_listview.setadapter (Newsadapter); Newsadapter.notifydatasetchanged ();

Because there are headview, so there is still a problem, this time adjusted the next Headview

Become

News.clear (); News.addall (LocalNews);

Newsadapter=new Newslistadapter (activity, News);

if (Mnews_listview.getheaderviewscount () >0) {

Mnews_listview.removeheaderview (viewgallery);} Mnews_listview.addheaderview (Viewgallery); Mnews_listview.setadapter (Newsadapter); Newsadapter.notifydatasetchanged ();

OK, no problem.

It should be that the async thread did not update the data in a timely manner under this note

ListView encounters a Problem Java.lang.IndexOutOfBoundsException:Invalid index 0, size is 0

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.