//get the lat and loni throgh the loaddata function.java.util.ConcurrentModificationException at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:64) How to resolve it?Somebody said use Iterator.
public void loaddata()
{
try
{
lat = new String[vechno.length];
lon=new String[vechno.length];
for(int i=0;i<vechno.length;i++)
{
if(Integer.parseInt(vechspeed[i].trim())==0||vechspeed[i].trim()=="")
{
latiloni=call2(vechno[i].toString());
lat[i]=latiloni[0];
lon[i]=latiloni[1];
GeoPoint point1 = new GeoPoint((int)(Double.parseDouble(lat[i])*1E6),(int)(Double.parseDouble(lon[i])*1E6));
OverlayItem overlayItem = new OverlayItem(point1,"Vehicle No : "+vechno[i]+"(Idle)",
"Located : "+vechloc[i]+"\n"+"Speed(kmph) : "+vechspeed[i]+"\n"+"Address : "+vechadd[i]);
itemizedOverlay0.addOverlay(overlayItem);
final MapController mc = mapView.getController();
mc.animateTo(point1);
mc.setZoom(6);
mapOverlays.add(itemizedOverlay0);
}
else
if(Integer.parseInt(vechspeed[i].trim())>=1&&Integer.parseInt(vechspeed[i].trim())<=20)
{
latiloni=call2(vechno[i].toString());
lat[i]=latiloni[0];
lon[i]=latiloni[1];
GeoPoint point2 = new GeoPoint((int)(Double.parseDouble(lat[i])*1E6),(int)(Double.parseDouble(lon[i])*1E6));
OverlayItem overlayItem = new OverlayItem(point2,"Vehicle No : "+vechno[i]+"(Running)",
"Located : "+vechloc[i]+"\n"+"Speed(kmph) : "+vechspeed[i]+"\n"+"Address : "+vechadd[i]);
itemizedOverlay1.addOverlay(overlayItem);
final MapController mc = mapView.getController();
mc.animateTo(point2);
mc.setZoom(6);
mapOverlays.add(itemizedOverlay1);
}
else
if(Integer.parseInt(vechspeed[i].trim())>=21&&Integer.parseInt(vechspeed[i].trim())<=40)
{
latiloni=call2(vechno[i].toString());
lat[i]=latiloni[0];
lon[i]=latiloni[1];
GeoPoint point3 = new GeoPoint((int)(Double.parseDouble(lat[i])*1E6),(int)(Double.parseDouble(lon[i])*1E6));
OverlayItem overlayItem = new OverlayItem(point3,"Vehicle No : "+vechno[i]+"(Running)",
"Located : "+vechloc[i]+"\n"+"Speed(kmph) : "+vechspeed[i]+"\n"+"Address : "+vechadd[i]);
itemizedOverlay2.addOverlay(overlayItem);
final MapController mc = mapView.getController();
mc.animateTo(point3);
mc.setZoom(6);
mapOverlays.add(itemizedOverlay2);
}
else
if(Integer.parseInt(vechspeed[i].trim())>=41&&Integer.parseInt(vechspeed[i].trim())<=60)
{
latiloni=call2(vechno[i].toString());
lat[i]=latiloni[0];
lon[i]=latiloni[1];
GeoPoint point4 = new GeoPoint((int)(Double.parseDouble(lat[i])*1E6),(int)(Double.parseDouble(lon[i])*1E6));
OverlayItem overlayItem = new OverlayItem(point4,"Vehicle No : "+vechno[i]+"(Running)",
"Located : "+vechloc[i]+"\n"+"Speed(kmph) : "+vechspeed[i]+"\n"+"Address : "+vechadd[i]);
itemizedOverlay3.addOverlay(overlayItem);
final MapController mc = mapView.getController();
mc.animateTo(point4);
mc.setZoom(6);
mapOverlays.add(itemizedOverlay3);
}
else
if(Integer.parseInt(vechspeed[i].trim())>=61&&Integer.parseInt(vechspeed[i].trim())<=80)
{
latiloni=call2(vechno[i].toString());
lat[i]=latiloni[0];
lon[i]=latiloni[1];
GeoPoint point5 = new GeoPoint((int)(Double.parseDouble(lat[i])*1E6),(int)(Double.parseDouble(lon[i])*1E6));
OverlayItem overlayItem = new OverlayItem(point5,"Vehicle No : "+vechno[i]+"(Running)",
"Located : "+vechloc[i]+"\n"+"Speed(kmph) : "+vechspeed[i]+"\n"+"Address : "+vechadd[i]);
itemizedOverlay4.addOverlay(overlayItem);
final MapController mc = mapView.getController();
mc.animateTo(point5);
mc.setZoom(6);
mapOverlays.add(itemizedOverlay4);
}
else
if(Integer.parseInt(vechspeed[i].trim())>=81&&Integer.parseInt(vechspeed[i].trim())<=120)
{
latiloni=call2(vechno[i].toString());
lat[i]=latiloni[0];
lon[i]=latiloni[1];
GeoPoint point6 = new GeoPoint((int)(Double.parseDouble(lat[i])*1E6),(int)(Double.parseDouble(lon[i])*1E6));
OverlayItem overlayItem6 = new OverlayItem(point6,"Vehicle No : "+vechno[i]+"(Running)",
"Located : "+vechloc[i]+"\n"+"Speed(kmph) : "+vechspeed[i]+"\n"+"Address : "+vechadd[i]);
itemizedOverlay5.addOverlay(overlayItem6);
final MapController mc = mapView.getController();
mc.animateTo(point6);
mc.setZoom(6);
mapOverlays.add(itemizedOverlay5);
}
else
if(Integer.parseInt(vechspeed[i].trim())>=120&&Integer.parseInt(vechspeed[i].trim())<=150)
{
latiloni=call2(vechno[i].toString());
lat[i]=latiloni[0];
lon[i]=latiloni[1];
GeoPoint point7 = new GeoPoint((int)(Double.parseDouble(lat[i])*1E6),(int)(Double.parseDouble(lon[i])*1E6));
OverlayItem overlayItem = new OverlayItem(point7,"Vehicle No : "+vechno[i]+"(Running)",
"Located : "+vechloc[i]+"\n"+"Speed(kmph) : "+vechspeed[i]+"\n"+"Address : "+vechadd[i]);
itemizedOverlay6.addOverlay(overlayItem);
final MapController mc = mapView.getController();
mc.animateTo(point7);
mc.setZoom(6);
mapOverlays.add(itemizedOverlay6);
}
}
mapView.invalidate();
}
catch(Exception e)
{
}
}
protected void dosomthing()
{
progressdialog1=ProgressDialog.show(Mapping.this, "", "Loading.Please wait...");
Runnable threadTask = new Runnable() {
@Override
public void run() {
while(true){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
loaddata();
messageHandler.sendEmptyMessage(0);
}
}
};
(new Thread(threadTask)).start();
}
It is difficult to see exactly where the exception is coming from, and I suspect that it is not actually in the code you are showing us. If you provided a full stack trace, highlighted the lines in your code that correspond to the line numbers in the trace, we could maybe track it down.
So what causes
ConcurrentModificationExceptions? Well basically, they happen when a collection is modified while anIteratorfor the collection is being used; e.g. like this:is likely to throw a CME on the 2nd line if it ever finds a
"42". The way to avoid CMEs is to not modify collections while iterating them … or while some other thread might be iterating them.There are a couple of ways to get around this:
The ConcurrentCxxx collection classes provide iterators that won’t throw a CME. The downside is that they are a more expensive for normal (single-threaded) use than the analogous
java.utilimplementation classes.If you are iterating the list in order to remove elements, you can do this using the
Iterator.remove()method; e.g.However, this only works for this particular use-case. You can’t add or replace list elements like this.