iterator hasnext () zwraca true, ale next () zgłasza NoSuchElementException
Kiedy debugowałem mój kod, odkryłem, żehasNext()
metodaIterator
zwróconytrue
, alenext()
metoda rzuciła NoSuchElementException.
Poniżej znajduje się mój kod:
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();
}
}
Co się mylę?