I'm making a game kind of like Super Smash Bros. One of the attacks available to the player is a projectile fireball. All the fireball animation and collision is working perfectly, but whenever the code goes to remove a projectile from the screen, I get the following exception:
1 2 3 4 5 6
| 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 Main.run(Main.java:213) at Main.<init>(Main.java:67) at Main.main(Main.java:307) |
I'm using the following code for looping and removing:
1 2 3 4 5 6 7 8 9 10 11
|
for(Attack a: projectiles) { a.update(bg); }
public void removeFromWorld() { Main.projectiles.remove(this); } |
Currently I'm using an ArrayList to hold all the projectile data. Would it help if I used a different type of array or made a flag in the projectile class that indicated that the projectile should no longer be updated/drawn?
Thanks for the help!