arraylist - java.util.ConcurrentModificationException Cant fix -


public game() {         gamestate = overworld;          objects = new arraylist<gameobject>();         remove = new arraylist<gameobject>();          battleobjects = new arraylist<gameobject>();         battleremove = new arraylist<gameobject>();          player = new player(display.getwidth() / 2 - player.size / 2, display.getheight() / 2 - player.size / 2);          objects.add(player);         objects.add(new circle(32, 32, player));         objects.add(new imp(300, 100, player));     }   public void update() {             if (gamestate == battle) {                 (gameobject : battleobjects) {                     if (!i.isremoved())                         i.update();                     else                         battleremove.add(i);                 }             }             else {                 (gameobject : objects) {                     if (!i.isremoved())                         i.update();                     else                         remove.add(i);                 }             }         }          public void render() {             if (gamestate == battle) {                 (gameobject : battleobjects)                         i.render();             }             else {                 (gameobject : objects)                     i.render();             }         }          public static void createnewbattle(player p, monster m) {             battleobjects.add(p);             battleobjects.add(m);              gamestate = battle;         } 

i understand why happening cannot life of me find way fix problem... can me??? sat here hours trying find way of doing this. think of creating array battle objects.

the safe way modify collection using remove method iterator, use iterator instead of each , fine: iterating through collection, avoiding concurrentmodificationexception when removing in loop


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -