开发者

ConcurrentModificationException in MapActivity

this is my first question here, so if anything's wrong, do tell.

Now, I have a public class MainMap extends MapActivity which uses a MyLocationListener for the user's location and a HelloItemizedOverlay. I'm getting certain POI's from an XML-file which I want to add markers (pretty basic Overlays).

User presses a button, AsyncTask starts:

private class GetPOITask extends AsyncTask<String, Void, Void> {

 protected Void doInBackground(String... params) {
    clearMapOverlay();
    if(!isBusyAddingOverlays)
    {
       connect(params[0]);
    }
    return null;
 }

 protected void onPreExecute() {
  clearMapOverlay();
 }
}

Clearing out the MapOverlay (this.mv is a MapView):

public void clearMapOverlay()
 {
  this.mv.getOverlays().remove(placesItemizedOverlay);
  this.mv.postInvalidate();
  this.mv.getOverlays().add(myLoc);
 }

This is the method that my connect-method calls when I have enough information to add a marker:

private void addOverlayToList(int id, GeoPoint point, Str开发者_如何学运维ing title, String description)
{
 //Log.e("Debug", "Adding overlay");
 placesItemizedOverlay.addOverlay(new POIOverlay(id, point, title, description));
 this.mv.getOverlays().add(placesItemizedOverlay);
}

That should be all the relevant code.

The problem is that when I add the POI's and zoom the map (or move it), I get a ConcurrentModificationException.

I've searched through this site, reading similar threads (this one for example) but I can't really find what I'm doing wrong.

Knowing myself, it's probably something obvious.

Thanks in advance,

iarwain


This could come from the fact that addOverlayToList() is called from connect() which is called in a different Thread (doInBackground()). Only the thread wich initiated the UI can touch its views.

Move the add overlay calls into onPostExecute() (which you should override) of GetPOITask.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜