Concurrent Modification Exception : adding to an ArrayList

前端 未结 10 996
醉梦人生
醉梦人生 2020-11-22 10:53

The problem occurs at

Element element = it.next();

And this code which contains that line, is inside of an OnTouchEvent

10条回答
  •  [愿得一人]
    2020-11-22 11:31

    I normally use something like this:

    for (Element element : new ArrayList(mElements)) {
        ...
    }
    

    quick, clean and bug-free

    another option is to use CopyOnWriteArrayList

提交回复
热议问题