Solved Concurrent Modificaion Expection

Discussion in 'Plugin Development' started by Creeoer, Jan 11, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Creeoer

    I looked up the expection, apparently if you are iterating through a list and changing it at the same (or another thread is) it throws this eror, any help walking through this

    Code:
    Code:
            for (Block b : e.blockList()){
                       if (b.getLocation().getY() == -1 || b.getLocation().getY() == 0) {
                      
                           e.blockList().remove(b);
                       }
                       
     
  2. Offline

    Skionz

  3. Offline

    Creeoer

    @Skionz
    Iterator<Block> list = e.blockList().iterator();


    while (list.hasNext()) {
    Block b = (Block) list.next();
    if (b.getLocation().getY() == -1 || b.getLocation().getY() == 0) {

    e.blockList().remove(b);

    }

    Still nothing, now if I remember correctly do iterators go from end to beginning? So should I use list.hasPrevious?
     
  4. Offline

    teej107

    @Creeoer Nothing? So you aren't getting an error now?
     
  5. Offline

    Creeoer

    @teej107
    Sorry, no I'm getting the concurrency error yes.
     
  6. Offline

    teej107

    @Creeoer Remove the the object from the iterator rather than the List.
     
Thread Status:
Not open for further replies.

Share This Page