0

Trying to wrap up a project. Everything works in it except it can't instantiate the animal into the designated array. This line is code that my instructor gave me, so I'm at even more of a loss. This is what I used to declare the array list:

private static ArrayList<Dog> dogList = new ArrayList<Dog>();

I then collect the information I needed and use the code below to try and add it to the array list. nthDog is a previously declared variable and the parameters are correct.

 Dog nthDog = new Dog(name, breed, gender, age, weight, acquisitionDate,
            acquisitionCountry, trainingStatus, reserved, inServiceCountry);
 dogList.add(nthDog);

This code was sent to me by my instructor, however, when used it pulls up the errors ConcurrentModificationException and checkForComodification. Can't figure out what could be wrong.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Melony
  • 1

1 Answers1

0

You might be modifying a collection directly while it is iterating over the collection with a fail-fast iterator, the iterator will throw this exception.

For more details on ConcurrentModificationException Please refer https://docs.oracle.com/javase/7/docs/api/java/util/ConcurrentModificationException.html

Vipul
  • 816
  • 4
  • 11
  • 26