So basically I have an array which holds players names, and the method checks through the names before processing whats next.
Ex.
Code:
for (String comdAdvisor : nameList) {
Declaration:
Code:
public static List<String> nameList;
In loading method to initiate array list:
Code:
nameList = new ArrayList<String>();
nameList.add("no entry");
the above code this works fine, but when i go to add a person's name to the arrayList while it is looping (game running) it gives an error:
Code:
ConcurrentModificationException
This is because the array can't be modified while its being looped through which causes a null.
Code to add the players name: (name is correct)
Code:
nameList.add(name);
After googling this, others had the same issue with their java projects and said to use an iterator for it as it will safely add in new elements to an array without causing it to throw an error. Although, I have never really worked with an iterator for an array before and any help would be greatly appreciated thanks.
I understand if some stuff is unclear, please post if you need clarification. Thanks!