0
    testSed4 = sedenia4.get(0);

    while (it8.hasNext()) {
        tempRozdiel = it8.next();
        tempSed4 = it7.next();

        if (testSed4.equals(tempSed4)) {
            testSed4 = tempSed4;
            casy.add(tempRozdiel);
        } else {
            casy.add(hodnota);
            testSed4 = tempSed4;
        }
    }
    for (int j = 0; j < casy.size(); j++) {
        System.out.println(casy.get(j) + " casy");
    }

Why I have error in line: tempRozdiel = it8.next();

What is bad in this code ?

5
  • What kind of error do you get? If it is a nullpointerexception you forgot to initialize your it8 arraylist object. Commented Dec 4, 2012 at 15:50
  • Exception in thread "main" java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819) at java.util.ArrayList$Itr.next(ArrayList.java:791) at appidentifysession.AppIdentifySession.main(AppIdentifySession.java:36) Java Result: 1 Commented Dec 4, 2012 at 15:53
  • I can't get here full code because: "Oops! Your question couldn't be submitted because: Your post does not have much context to explain the code sections; please explain your scenario more clearly." What is bad on it ? Commented Dec 4, 2012 at 15:55
  • AppIdentifySession.java:36 is line which contains tempRozdiel = it8.next(); Commented Dec 4, 2012 at 15:56
  • What type of tempRozdiel and Iterator? Commented Dec 4, 2012 at 15:58

2 Answers 2

2

Exception happens because you are modifying the collection over which it is iterating within the body of the iteration loop.

This is a reason why you got ConcurrentModificationException from iterator.next()

Sign up to request clarification or add additional context in comments.

3 Comments

@Majkl 1st off we don't know what is going on in your code since you provided as not enough info. Something changes your list during this action (you posted). About at8 iterator: post info about this list
while (it1.hasNext()) { ipecka = it1.next(); agentik = it2.next(); spolu = ipecka + agentik; ipagent.add(spolu); } In this code is it OK, why not in next code?
I have first list_session which contains 1,2,2,3 .Second list_time contains 30,17,25,46 .When second element of list_session is equals with first element, then add this time to third list_cas else add -1 .The same for third element and fourth etc.
1
while (it8.hasNext()) {
    tempRozdiel = it8.next();
    tempSed4 = it7.next();

You are only checking if it8 has a next element, but not for it7.

Furthermore, you cannot use casy.add() if it7 or it8 are iterators on this object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.