Possible Duplicate:
java.util.ConcurrentModificationException on ArrayList
I am trying to remove items from a list inside a thread. I am getting the ConcurrentModificationException
. I read from this link that it's related to removing items from list. I am putting the sample code below. How can I do this properly without this exception in my case.
try
{
for(Game game:appDeleg.getGlobalGames().getGames())
{
if(game.getOwner().getId().equals(params[0]))
{
synchronized (appDeleg.getGlobalGames().getGames())
{
appDeleg.getGlobalGames().getGames().remove(game);
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
return "noconnection";
}