Removing Object from ArrayList Breaks Program
<p>I was creating an sscce, but there was just way too much code to post it here, so I will post sections and hopefully you can follow!</p>

<p>So, I have this class called <code>Ship</code>, within the class there is this:</p>

<p><strong>Chunk 1:</strong></p>

<pre><code>keyboard.keyPress("SPACE", new Runnable(){

    @Override
    public void run(){
        Laser laser = new Laser(
                new Sprite("/media/images/laser.png"),
                sscce.Ship.this.room);
        sscce.Ship.this.room.addGameObjectAt(
                laser,
                sscce.Ship.this.getX() + (sscce.Ship.this.getWidth() / 2) - 3,
                sscce.Ship.this.getY());
    }
});
</code></pre>

<p>When the <kbd>Space</kbd> key is press it creates a <code>Laser</code> object and then we add it to the game where this object is stored within an <code>ArrayList</code> then draw to the screen in my main game loop, which loops through the <code>ArrayList</code>.</p>

<p><code>Laser</code> is a very simple class, it looks like this:</p>

<p><strong>Chunk 2:</strong></p>

<pre><code>package JGame.GameObject;

import JGame.Room.Room;

public class Laser extends GameObject{

    public Laser(Sprite sprite, Room room){
        super(sprite, room);
        move.moveToY(0 - this.getHeight(), 5, new Runnable(){
            @Override
            public void run(){
                Laser.this.destroy.destroyGameObject();
            }
        });
    }
}
</code></pre>

<p>So Chunk 1 create Chunk 2 then adds it to the array list. This all works fine and dandy!</p>

<p><strong>Chunk 3:</strong></p>

<pre><code>public void moveToY(int y, int speed, Runnable complete){
    this.obj.moveEndY = y;
    this.obj.moveAmountY = speed;
    this.complete = complete;
    this.obj.needsToMoveY = true;
}
</code></pre>

<p>This adds a move action to the newly created <code>Laser</code>. And then we move the object vertically (defined by chunk 2 and performed within the main game loop).</p>

<p>This next part is breaking the game, and by break I mean every thing stops (eventlisteners, movement, etc).</p>

<p>From Chunk 2 I say "When moveToY gets to its destination run the Runnable code" and the runnable code says to destroy the laser using <code>destroyGameObject()</code>. and the destory looks like this and is initialized in all of the Game Objects Constructors (<code>Laser</code>, <code>Ship</code> etc).</p>

<p><strong>Chunk 4:</strong></p>

<pre><code>package JGame.Actions;

import JGame.GameObject.GameObject;
import JGame.Room.Room;

public class DestroyAction extends Action{
    GameObject obj;
    Room room;
    public DestroyAction(Room room, GameObject obj){
        this.room = room;
        this.obj = obj;
    }

    public void destroyGameObject(){
        room.removeGameObject(this.obj);
    }
}
</code></pre>

<p>Chunk 4 just tells the room "Hey we need to remove this object from the list"</p>

<p><strong>Chunk 5:</strong></p>

<pre><code>public class Room extends JPanel implements Runnable{

    ArrayList&lt;GameObject&gt; gameObjects = new ArrayList&lt;&gt;();

    public void run(){
        try{
            while(true){
                // Do Event Listeners
                // Move objects along Y axis
                for(GameObject go : gameObjects){
                    if(go.needsToMoveY){
                        int objY = go.getY();
                        if(objY &gt; go.moveEndY){
                            go.setY(objY - go.moveAmountY);
                        }else if(objY &lt; go.moveEndY){
                            go.setY(objY + go.moveAmountY);
                        }else{
                            go.needsToMoveY = false;
                            // Executes Runnable parameter from moveToY()
                            go.move.actionComplete();
                        }
                    }
                }
                this.repaint();
                Thread.sleep(roomSpeed);
            }
        }catch(Exception e){
        }
    }

    public void removeGameObject(GameObject go){
        gameObjects.remove(go);
        System.gc();
    }
}
</code></pre>

<p>So, finally here in Chunk 5, this is the main loop a lot of code has been striped out but this tests if it should be moving, if it is done, run actionComplete() which was passed in via moveToY() as the Runnable. Well, this Runnable says delete the object when it gets to it's location. And when it runs the code within the Runnable 1 time, EVERYTHING stops. Movements stop; so if 2+ lasers were fired they should move upwards but they stop at their position and don't move. Keyboard buttons stop working, so the arrows to move the <code>Ship</code> no longer respond so you can navigate the ship up/down/left/right it just sits at it's last position of at the point where the Runnable was triggered for the first time.</p>

<p>So... Why is everything stopping? I just want to remove the object that was in the Runnable.</p>
