java.util.ConcurrentModificationException on surfaceView
<p>im developing a game on android and im having trouble with a loop, that iterates an ArrayList of Zombies. if i substract zombies the app still running, but when i add zombies the app randomly crashes.
I i know that the problem starts when i add an item to the zombies ArrayList, and makes that makes the thread throw an exception.</p>

<p>here it is the exception that i got from the LogCat</p>

<pre><code>07-19 20:55:02.960: ERROR/AndroidRuntime(19526): FATAL EXCEPTION: Thread-9
07-19 20:55:02.960: ERROR/AndroidRuntime(19526): java.util.ConcurrentModificationException
07-19 20:55:02.960: ERROR/AndroidRuntime(19526):     at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
07-19 20:55:02.960: ERROR/AndroidRuntime(19526):     at com.funkytron.android.killthemall.GameView.onDraw(GameView.java:131)
07-19 20:55:02.960: ERROR/AndroidRuntime(19526):     at com.funkytron.android.killthemall.GameLoopThread.run(GameLoopThread.java:34)
</code></pre>

<p>And here are the lines where i iterate the zombies ArrayList and if any zombie collides with a sprite it kill them and add a zombie</p>

<pre><code>        for (Iterator&lt;Zombie&gt; zombieIterator = zombieCollection.iterator(); zombieIterator.hasNext();)
        {
            Zombie zombie = zombieIterator.next();
                zombie.onDraw(canvas);

                for(Iterator&lt;Sprite&gt; sprite = sprites.iterator(); sprite.hasNext();)
                {
                    Sprite s = sprite.next();
                    if(zombie.isCollision(s.getX(), s.getY()))
                    {
                        die(s, zombie.getX(), zombie.getY());
                        break;
                    }
                }

        }
</code></pre>

<p>And  the die method</p>

<pre><code>public void die(Sprite sprite, float x, float y)
{
    sprites.remove(sprite);
    zombieCollection.add(createZombie(R.drawable.zombie,0,0));
    temps.add(new TempSprite(temps, this, x, y, bmpBlood));
    addPoints = true;
}
</code></pre>

<p>I tried to use a temp ArrayList, but it throws the same exception, i hope you can understand my ugly english</p>
