I am writing a program as part of a tutorial for a beginner Java student. I have the following method, and whenever I run it, it gives me the following exception:
java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372) at java.util.AbstractList$Itr.next(AbstractList.java:343) at Warehouse.receive(Warehouse.java:48) at MainClass.main(MainClass.java:13)
Here is the method itself, inside the Warehouse class:
public void receive(MusicMedia product, int quantity) { if ( myCatalog.size() != 0) {
The problem seems to be related to the if else statement. If I do not enable if else, the program will start, although it will not work properly, because the loop will not go through an empty ArrayList.
I tried to add the product so that it was not empty in other parts of the code, but it still gives me the same error. Any ideas?
source share