• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Concurrent Modifiaction Exception

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sneha Kashyap
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 22785
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out this thread.
 
Popeye has his spinach. I have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic