I don't understand why this method throws an exception:
public void add(Object obj){
gameObjects.add(obj); //here the exception happens
}
... while this one doesn't:
public void add(Object obj){
gameObjects.add(obj); // no exception actually happens here
gameObjects.remove(obj);
}
Why does this happen, considering that is it a run time exception?
Exception:
Exception in thread "Thread-0" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
at java.util.ArrayList$Itr.next(Unknown Source)
at threads.Main.tick(Main.java:181)
at threads.Main.run(Main.java:104)
The method is called for a tick method inside an object.
gameObjects
isn't null:
List<Object> gameObjects = new ArrayList<Object>(128);