• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem removing object from ArrayList - java.util.ConcurrentModificationException  RSS feed

 
Bod MacNeil
Ranch Hand
Posts: 62
2
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all.  I'm having problems with removing items from my ArrayList;  In this program it creates a new shark object every 2 seconds and adds it to an ArrayList of Shark objects.   Once the shark reaches the end of the screen it should then remove the shark from the array list.  But I'm getting a java.util.ConcurrentModificationException.  I have posted the snipped of code I'm using for the Iterator and also the method for creating the shark.  ANy help would be great and I can post more info if required.  thanks

//Iterator in render() method;


//createShark() method
 
Bod MacNeil
Ranch Hand
Posts: 62
2
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have fixed the problem for now.  I changed the line from sharks.remove(current) to sharkIterator.remove()  
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, that's exactly right. I gave you a cow for posting what you found, especially since it was right.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!