I have this code:
outlets is a ArrayList passed to the method; riverBasin is a 2D "matrix" of int (int[][] riverBasin);
for (int[] item: outlets) {
if (item[0] < 2 || item[0] > this.riverBasin.length - 1 || item[1] < 2 || item[1] > this.riverBasin[0].length - 1) {
System.out.println("This provisionally substitutes error catching. Outlet (" + item[0] + "," + item[1] + ") is not correct.");
outlets.remove(item);
System.out.println("Remaining outlets: ");
for (int[] atem: outlets) {
System.out.print("(" + atem[0] + "," + atem[1] + ")\n");
}
}
else {
this.riverBasin[item[0]][item[1]] = 10;
}
}
removing the "item" from the ArrayList outlets generate an error:
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at org.geoframe.ocn.Eden.setMultipleOutlet(Eden.java:135)
at org.geoframe.ocn.Eden.main(Eden.java:205)
which I do not really completely understand. I suspect, however, that I broke the iterator. Correct ? How could then I remove the unwanted elements in the ArrayList.
Thank you in advance for any help,
riccardo