This will be a problem of simultaneous modification. This is the only way to get this error.
The reason you are not getting a simultaneous modification error is because the way you execute the loop does not create an iterator, and therefore there is no way to modify the error at the same time.
I suggest synchronizing your arraylist or using something like CopyOnWriteArrayList .
Edit: Sorry CopyOnWrite will not work for this particular problem. To do this, you need to switch to the foreach loop.
In response to your comment below:
Synchronization:
synchronized(elipsasCol){ for (int i = 1; i < elipsasCol.size(); i++) { if (elipsasCol.get(i) != null && elipsasCol.get(i).contains(mouse)) { // This line double modulo = Math.sqrt(Math.pow(mouse.x - elipsasCol.get(i).getCenterX(), 2) + Math.pow(mouse.y - elipsasCol.get(i).getCenterY(), 2)); } }
and then add similar synchronized(elipsasCol){}
anywhere you touch elipsasCol
.
or
for (T obj : elipsasCol) { if (obj != null && obj.contains(mouse)) { // This line double modulo = Math.sqrt(Math.pow(mouse.x - obj.getCenterX(), 2) + Math.pow(mouse.y - obj.getCenterY(), 2)); } }
which is likely to cause a simultaneous modification error. At this point, you can switch the ArrayList to CopyOnWriteArrayList or synchronize it.
source share