Results 1 to 3 of 3
  1. #1
    user92 is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default java.util.ConcurrentModificationException

    i want to delete the first element in my linklist in java but i have this exception java.util.ConcurrentModificationException and i cant delete it
    can you please tell me how i fix this error ?
    This is my code:
    public static void Del()
    {

    String name1;

    stuff1 obj =new stuff1 (null,0,0,0,0);
    Scanner read = new Scanner(System.in);

    if (catalog.isEmpty())
    {System.out.println("Linked list is empty");}

    else
    {
    System.out.println("Enter the name of the product to delete ");
    ///obj.setName(read.next());
    name1=read.next();
    Iterator<stuff1> i3 = catalog.iterator();
    // Iterator i4 = catalog.iterator();

    while (i3.hasNext()) {

    stuff1 dmy= (stuff1) i3.next(); //error ????
    if(dmy.getName().matches(name1)){
    catalog.remove(dmy);

    }

    }

    System.out.println();
    System.out.println();

    }

    }//end delete linkedlist java

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: java.util.ConcurrentModificationException

    You cannot make changes to a List while your are iterating over it else you get the exception you are seeing. Try using a method of the Iterator interface instead.

  3. #3
    user92 is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

Similar Threads

  1. java.util.ConcurrentModificationException
    By mharsijamel in forum New To Java
    Replies: 1
    Last Post: 11-02-2011, 03:40 PM
  2. I'm getting a ConcurrentModificationException
    By gib65 in forum Advanced Java
    Replies: 6
    Last Post: 08-18-2010, 10:45 PM
  3. Getting around a ConcurrentModificationException
    By Newbie666 in forum New To Java
    Replies: 50
    Last Post: 01-26-2010, 03:30 PM
  4. Replies: 19
    Last Post: 08-28-2009, 01:49 AM
  5. ConcurrentModificationException with ArrayList
    By fogus in forum New To Java
    Replies: 3
    Last Post: 01-15-2009, 05:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •