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:
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:
//looping, this is inside the class that draws everything
for(Attack a: projectiles)
{
a.update(bg);
}
//removing this is inside the projectile class
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!