Hello I have an ArrayList of Notecard objects. The code I have looks through the ArrayList for a Notecard object of the same title and removes it. Then the updated ArrayList is rewritten onto a file.
public void deleteThisNote() {
for (NoteCard card : notecardList) {
if (noteCardTitle.equals(card.getNoteCardTitle())) {
notecardList.remove(card);
try {
FileOutputStream fos = openFileOutput("rootFile", MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(notecardList);
fos.close();
oos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
This is the log that is printed out when it crashes:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dlimited.mydolist, PID: 8620
java.util.ConcurrentModificationException
at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
at com.dlimited.mydolist.NoteEdit.deleteThisNote(NoteEdit.java:119)
at com.dlimited.mydolist.NoteEdit$2$1.onClick(NoteEdit.java:101)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
What am I doing wrong here? Also is there a better way of deleting? Any help is much appreciated.