When I debugged my code I found that the hasNext()
method of Iterator
returned true
, but the next()
method threw NoSuchElementException.
Below is my code:
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();
}
}
What am I getting wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…