我在处理地图(使用GetDirection应用程序接口在地图上绘制线条)时遇到此错误。我曾经使用过CopyOnWriteArrayList,但它有时会抛出ConcurrentModification异常。
CopyOnWriteArrayList<GeoPoint> pointArray;
pointArray = parcer.getDirectionParcer(jsonObject);
GeoPoint gp1;
GeoPoint gp2 = src;
Iterator<GeoPoint> it1 = pointArray.iterator();
//for(int i=0;i<pointArray.size();i++) // the last one would be crash
Utility.debugger("2");
while (it1.hasNext()) {
try {
gp1 = gp2;
gp2 = (GeoPoint) it1.next();
mMapView.getOverlays().add(new MyOverLay(gp1,gp2,2,color));
} catch (ConcurrentModificationException e) {
Utility.debugger("exception");
e.printStackTrace();
}
}它在it1.next()中给出错误。
发布于 2011-11-14 13:23:53
您是否在非UI线程中调用此代码?
ConcurrentModificationException可能是由于在UI线程试图访问覆盖时在非UI线程中添加了覆盖。您只能修改UI线程上的覆盖。
https://stackoverflow.com/questions/8117368
复制相似问题