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