java - Arraylist iterator: concurrentmodification -


The guardian is a java.util.ArrayList.

I am going through it again

Public Zero-Hit Occakments (Snake Controller Snake Controller) {ListEditator & lt; HTTP & gt; I = occupiers List indicator (); While (i.hasNext ()) {Hitable hitable = i.next (); If (hitable.hit (snakeController)) {// returns are correct if it should be removed i.remove (); }}}

I can understand why this would be a ConcurrenModificationException ... I am using libgdx, so there could be a threading problem This is my first libgdx project , So I'm not sure. Android code to run stacktrace:

java.util.AbstractList $ SimpleListIterator.remove (AbstractList.java:71) on com.ninovanhooff.snake.model.BoardSpace.hitOccupants .ConcurrentModificationException (BoardSpace.java: 65) com.ninovanhooff.snake.controller.SnakeController.act (SnakeController.java:77) com on com.ninovanhooff.snake.controller.BoardController.act (BoardController.java:72). ninovanhooff.snake.GameActor $ 2 .act (GameActor.java:77) com.badlogic.gdx.scenes.scene2d.Actor.act (Actor.java:86) on com.badlogic.gdx.scenes.scene2d.Group.act At (Group.java48) com.badlogic.gdx.scenes.scene2d.Group.act (Group.java:48 at com.badlogic.gdx.scenes.scene2d.Stage.act) (Stage.java, 22-25) com On .ninovanhooff.snake at. On SnakeGame.render (SnakeGame.java:66) com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame (AndroidGraphics.java:510) on android.opengl.GLSurfaceView $ GLThread.guardedRun (GLSurfaceView Java: 1516) android.opengl .GLSurfaceView $ GLThread.run (GLSurfaceView.java1240)

This exception can be thrown by methods, when such modification is not allowed, then concurrent amendment of an object is detected .

For example, it is generally not acceptable to modify the collection for a thread, while the second thread is running on it. In general, the outcome of the walk is undefined in these circumstances. Some Iterator implementations (including all general purpose collection implementations provided by the GRE) can be chosen to throw this exception when finding this behavior. Passengers who do this are known as unsuccessful Ierators, because they fail quickly and clearly, rather that they take the risk of arbitrary, non-deterministic behavior in the future indefinitely.

Can not modify the list, walk through it.

There are several ways:

1) Create a new list

2) Use different collections such as a map or set.

3) Change some state to hitable object


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -