In this android game, I'm using an ArrayList to keep track of all of the entities currently on the screen. Running through the list allows me to successfully update and add entities to the screen / list, but attempting to remove them gives me a java.util.ConcurrentModificationException error. I'm a novice programmer, so I don't really know what could be going wrong.
The method I'm using to determine when a entity needs to be removed ( when it goes offscreen, but only through the top ) is this.
private void deleteEntities() {
for(Entity ent : entsOnLevel) {
if((ent.getY() + ent.getImage().getHeight()) < 0) {
this.entsOnLevel.remove(ent);
}
}
}
Could someone explain to me what could be going wrong?