本文介紹了迭代器 hasext() 返回 true 但 next() 拋出 NoSuchElementException的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
當(dāng)我調(diào)試我的代碼時,我發(fā)現(xiàn) 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();
}
}
我做錯了什么?
推薦答案
當(dāng)我重新啟動服務(wù)器并重新部署我的應(yīng)用程序時,代碼工作正常,所以我猜代碼沒有錯,我無法理解 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!
這篇關(guān)于迭代器 hasext() 返回 true 但 next() 拋出 NoSuchElementException的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!