aspose file tools*
The moose likes Java in General and the fly likes Concurrent Modifiaction Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Concurrent Modifiaction Exception" Watch "Concurrent Modifiaction Exception" New topic
Author

Concurrent Modifiaction Exception

Sneha Kashyap
Greenhorn

Joined: May 06, 2009
Posts: 22
Hi,
I'm new to java, I'm nt bale to fix this exception Concurrent Modifiaction, I used a file to read data from it and store it on a linked list
data in my file is of the form
Slno Name
01 abc
01 def
02 abc
03 xyz
then i read it from the linked list and then store it by grouping them into intemsets using multimaps Map<String, List<String>>.

I need data to be stored like this:
01 {abc,def}
02 {abc}
03 {xyz}


Data gets stored on to the linked list but I'm unable to read it from the list and store it on to multimaps.

These are the errors I'm getting:
java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(Unknown Source)
at java.util.LinkedList$ListItr.next(Unknown Source)
at Itemset.main(Itemset.java:41)


I am sure there is a better way to do this, Please help me and let me know how to fix this exception or a better way to do this.


Thanks in advance.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

The error happens when you modify a collection that you're actively iterating over; i.e., if you have a Iterator, and the collection is modified, the next time you use the Iterator, this exception can happen. If you can use a ListIterator instead of an Iterator, that class lets you delete items through the iterator, if that's what you need to do.


[Jess in Action][AskingGoodQuestions]
Sneha Kashyap
Greenhorn

Joined: May 06, 2009
Posts: 22
Hi,

I have used listiterator but still happen to get the same exception.
Please tell me how to do it.Can this be achieved using a different collection if so which should be used?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Ernest Friedman-Hill wrote: If you can use a ListIterator instead of an Iterator, that class lets you delete items through the iterator, if that's what you need to do.


Still you can remove/delete an items in the List by Iterator . ListIterator provides extra add() method .
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Seetharaman Venkatasamy wrote:

Still you can remove/delete an items in the List by Iterator . ListIterator provides extra add() method .


You're right, of course. Posting before coffee is never a good idea

In any case, let's see the main() method in Itemset.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Check out this thread.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: Concurrent Modifiaction Exception