Neil Veebrun

Greenhorn
+ Follow
since Dec 09, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Neil Veebrun

Hi Stephan,

Thanks for the helpful and quick reply. Your advice to return a new iterator every time on the iterator() method has fixed the problem. I no longer get an exception.

Cheers,

Neil
12 years ago
Hi there,

I'm fairly new to programming. I was hoping for some help understanding where I might be going wrong when I inherit from Iterator to make a "safe" iterator, please. This is one that can be used by a client object to iterate through the collection, but not remove anything from it.

When I run my program, I get a ConcurrentModificationException as the Client object's printProducts() method is called and I'm not sure why. Here is the relevant code:



And this is the exception:

Exception in thread "main" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:782)
at java.util.ArrayList$Itr.next(ArrayList.java:754)
at SafeIterator.next(SafeIterator.java:11)
at SafeIterator.next(SafeIterator.java:1)
at Client.printProducts(Client.java:16)
at Client.<init>(Client.java:8)
at Main.main(Main.java:8)

Help much appreciated.

Thanks,

Neil
12 years ago