Presumably in one of your implementations of GameComponent -I guess the start button- the updateComponent() method removes all the entries from the ArrayList of components because you are no longer on the menu so they aren't there anymore. Am I right? You cannot do this. You are iterating over the list (a for-each loop creates an Iterator object in the background) so the ArrayList will not let you modify it. If you could then the Iterator might try to access an element that no longer exists or has been moved etc... So it can't be done.
The easiest solution (IMO) is to use a message queue which at its simplest is an ArrayList of runnable objects. When you want something to be done but cannot do it at the current time, because you are in an iteration loop or the wrong thread etc, you add a message to the queue containing the code you want done. At a convenient time you run the code in each message then clear the queue.
//Add this in the field declarations of Window.
public static final ArrayList<Runnable> messageQueue = new ArrayList<>();
//...
//Modifying onTick()
public void onTick() {
for (GameComponent g : windowComponents) {
g.updateComponent();
}
for(Runnable r: messageQueue) {
r.run();
}
messageQueue.clear();
}
//An example of clearing the components from a component class.
@Override
public void updateComponent() {
Window.messageQueue.add(
new Runnable() {
@Override
public void run() {
//Whatever you do to remove components.
}
}
);
}
This is a very simple, naive implementation. It should work for what you have described but I would advise refining it if you ever want to use it for anything else. But the concept is there.
A little advice - when you have an exception and you don't know why. Just google the name of the exception - you will get the javadoc for it which will most likely tell you the most likely causes for it.
A little more advice - When people give you advice, take it - you are still not using the code blocks for this site and it makes your code very hard to read.