Sam
05/20/2020, 4:13 AMFatal Exception: java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.next(ArrayList.java:860)
My code:
val dataConversation = ArrayList<Conversation>() // global
// in background ( I have use Epoxy - Airbnb )
val cloneListConcurrency = arrayListOf<Conversation>().apply { addAll(dataConversation) }
with(cloneListConcurrency.iterator()) {
forEach {
// do something to display
}}
// in background
fun deleteConversation(conversationId: String?) {
for (index in 0 until dataConversation.size) {
val item = dataConversation[index]
if (item.id == conversationId) {
dataConversation.removeAt(index)
break
}
}
}
Many Thanks.Arun
05/20/2020, 4:17 AMCopyOnWriteArrayList
which is thread safe.
However a proper fix for this is to use immutable lists and publish new list to epoxy on changes. Epoxy internally does diffing to find the changed items.
In this case, if you want to delete an item, delete it outside of epoxy and pass a new list to epoxy. Epoxy will take care of rendering it.Sam
05/20/2020, 4:22 AMgildor
05/20/2020, 4:24 AMgildor
05/20/2020, 4:26 AMgildor
05/20/2020, 4:29 AMSam
05/20/2020, 4:29 AMgildor
05/20/2020, 4:30 AMSubhrajyoti Sen
05/20/2020, 9:08 AMSam
05/22/2020, 2:05 AMval cloneListConcurrency = CopyOnWriteArrayList<Conversation>(dataConversation)
with(cloneListConcurrency.iterator()) {
//todo something
}
/// modify outside with (CRUD
dataConversation
And I have one crash Fatal Exception: java.lang.NegativeArraySizeException -1
=> so how can I resolve two issues?
Thanks….Sam
05/22/2020, 2:13 AMgildor
05/22/2020, 2:30 AMgildor
05/22/2020, 2:30 AMCopyOnWriteArrayList<Conversation>(dataConversation)
gildor
05/22/2020, 2:30 AMSam
05/22/2020, 2:32 AMgildor
05/22/2020, 2:45 AMit not remove item while delete out of listWhat do you mean?
Sam
05/22/2020, 3:35 AM