First of all: Don't use enhanced for loop on Android if you're using an ArrayList
. It's slower than the regular one and uses more memory. For all other collections, it's OK.
What you're experiencing probably relates to non-synchronized modification of the collection. If the size suddenly changes while the loop is running, it'll cause errors like that one.