I have the following code:
Iterator<ggItem> iter = ggItemTimestampMap.keySet().iterator();
ggItem gg;
while (iter.hasNext()) {
gg = iter.next();
if (DateTime.now().isAfter(ggItemTimestampMap.get(gg).plusSeconds(10))) {
Log.v("ggItem 10 second limit:", gg.toString());
//If it hasn't been seen 10 seconds after its last timestamp. Remove it from the ArrayList and remove it from the ggItemTimeStampMap HashMap.
ggItemTimestampMap.remove(gg); //TODO probable problem causer.
removeggItemFromList(gg);
}
}
I get a ConcurrentModificationException
error on the iter.next();
call and am uncertain why?
I realize you cannot both access a hashmap of object keys and timestamp values and modify it at the same time, but doesn't the iterator counteract that?