java.util.NoSuchElementException解决办法
最近在做一个项目,项目运行时,总是提示:java.util.NoSuchElementException.错误没有具体到code的行号,所以不容易debug.
今天总算找到了root cause,so share it:
报错信息:
Exception in thread "main" java.util.NoSuchElementException at java.util.AbstractList$Itr.next(AbstractList.java:350) at sprint.reporter.SprintReporter.process(Unknown Source) at sprint.main.SprintMain.main(Unknown Source) Java Result: 1
报错位置:
猜测是某个interator出现了越界.
while(iter.hasNext()) { ArrayList<SprintUserStory> undoneUserStoriesList = SprintUtil.getUndoneUserStoriesList(iter.next().getID(),iter.next().getPkey()); //Root cause if(undoneUserStoriesList.size() >0){ willdonefeautre--; }
改正:
Root cause其实就是多用了一次iter.next(),所以报了迭代器错误。
while (iter.hasNext()) { JIRAFeature jirafeaturetemp = iter.next(); ArrayList<SprintUserStory> undoneUserStoriesList = SprintUtil.getUndoneUserStoriesList(jirafeaturetemp.getID(),jirafeaturetemp.getPkey()); if(undoneUserStoriesList.size() >0){ willdonefeautre--; }