Concurrent Modification Exception : adding to an ArrayList

前端 未结 10 998
醉梦人生
醉梦人生 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:20

    Well i have tried all the aspects in my case where i was iterating in an adapter a list but due to hitting again and again i showed me the message of exception being thrown . I tried Casting the list to

     = (CopyOnWriteArraylist)mylist.value;
    

    but it also throwed me an exception of CouldNotCastException,(and i finally pondered over the fact that why do they use or provide us a facality of casting).

    I even used the so called Synchronized Block too, but even it didn't worked or i might would have been using it in a wrong way.

    Thus it's all when i finally used the #all of time# Technique of handling the exception in try catch block, and it worked So put your code in the

    try{
    //block
    
    }catch(ConcurrentModificationException){
    //thus handling my code over here
    }
    

提交回复
热议问题