Recently in a project, when the project runs, always prompt: Java.util.NoSuchElementException. The error is not specific to the line number of code, so it is not easy to debug.
And today we finally found root cause,so share it:
Error message:
[Java] Exception in thread "main" java.util.NoSuchElementException
[Java] at Java.util.abstractlist$itr.next (abstractlist.java:350)
[Java] at sprint.reporter.SprintReporter.process (Unknown Source)
[Java] at Sprint.main.SprintMain.main (Unknown Source)
[Java] Java result:1
Error location:
Speculation is that some interator have crossed the border.
while (Iter.hasnext ()) {
arraylist<sprintuserstory> undoneuserstorieslist = sprintutil.getundoneuserstorieslist (Iter.next (). GetID (), Iter.next (). Getpkey ()); Root cause
if (Undoneuserstorieslist.size () >0) {
willdonefeautre--;
}
Correct:
Root cause is actually a multi-use Iter.next (), so reported an iterator error.
while (Iter.hasnext ()) {
Jirafeature jirafeaturetemp = Iter.next ();
arraylist<sprintuserstory> undoneuserstorieslist = Sprintutil.getundoneuserstorieslist ( Jirafeaturetemp.getid (), Jirafeaturetemp.getpkey ());
if (Undoneuserstorieslist.size () >0) {
willdonefeautre--;
}
Java.util.NoSuchElementException Solutions