本文介紹了迭代器 hasext() 返回 true 但 next() 拋出 NoSuchElementException的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
當我調試我的代碼時,我發現 Iterator
的 hasNext()
方法返回 true
,但是 next()
方法拋出 NoSuchElementException.
When I debugged my code I found that the hasNext()
method of Iterator
returned true
, but the next()
method threw NoSuchElementException.
下面是我的代碼:
Collection<TradeStock> restBuy=em.createQuery("select t from TradeStock ...t.getResultList();
if(!restBuy.isEmpty())
{
Iterator itrest=restBuy.iterator();
while(itrest.hasNext())
{
TradeStock ts=(TradeStock)itrest.next();
x+=ts.getTradeExecutedQuantity();
}
}
我做錯了什么?
推薦答案
當我重新啟動服務器并重新部署我的應用程序時,代碼工作正常,所以我猜代碼沒有錯,我無法理解 glassfish 的這種奇怪行為!
the code worked when i restarted the server and redeployed my app, so nothing was wrong with the code i guess, i cant understand this strange behavior of glassfish!
這篇關于迭代器 hasext() 返回 true 但 next() 拋出 NoSuchElementException的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!