ConcurrentModificationException

I keep getting this error with this code

	public boolean attackElement(int arrayIndex, int listIndex, int damage)
	{
		
		((Enemy)enemyList[ arrayIndex ].get(listIndex) ).attack(damage);
		if( ( (Enemy)enemyList[ arrayIndex].get(listIndex) ).getHp()<=0)
		{
			elementsArray[( (Enemy)enemyList[ arrayIndex].get(listIndex) ).getIdRow()][( (Enemy)enemyList[ arrayIndex].get(listIndex) ).getIdCol()] = null;
			enemyList[arrayIndex].remove(listIndex); // this code causes error
			return true;
		}
		else
			return false;
	}		

what does that mean? I read the definition but i didn’t understand it


Why starting a new thread for the same problem?

my bad lol, but why would this error happen?

Read the JavaDocs for that method

this might help you:
CopyOnWriteArrayList

its in java.util.List

if you read my first post , i said i already read the java docs but i didnt understand the circumstances for the error to happen.

But so i am guessing the error happens BECAUSE im trying to change the arrayList while im iterating through it? am i correct?

if that is the case, than whats some options that i could use???
wouldnt a CopyOnWriteArrayList be too slow

Ah ok! I understand now why I get this error (after making a few test appliacations),

My code was suppose to put the enemy in a different ArrayList each time he moves, but sometimes he would be in the same arrayList, and therefore adding to the current ArrayList while iterating through it at the same time will cause the error!!