Actually after pressing a button i have a method which check if in my itemStorico ArrayList exist new added items from itemModel, then if the item exist in the new list called itemModel i'm removing the old item from itemStorico and adding the new one, else just adding the new item without removing the old.
But i'm getting the following error:
2018-12-11 16:34:04.067 29033-29033/it.gabtamagnini.realco E/AndroidRuntime: FATAL EXCEPTION: main
Process: it.gabtamagnini.realco, PID: 29033
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.next(ArrayList.java:831)
at it.gabtamagnini.realco.OrdiniActivity.saveStorico(OrdiniActivity.java:1396)
at it.gabtamagnini.realco.OrdiniActivity$29.onClick(OrdiniActivity.java:1368)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22433)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6130)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
While here is the code from my method:
for(ItemModel itemModels : itemModel){
boolean exist = false;
for(ItemModel itemModel2 : itemStorico){
if(itemModels.getCodiceArticolo().contains(itemModel2.getCodiceArticolo())) {
itemStorico.remove(itemModel2);
itemStorico.add(itemModels);
exist = true;
}
}
if(!exist) {
itemStorico.add(itemModels);
}
}