powered by Jive Software

java.util.NoSuchElementException,why?

// Assume we’'ve created an MultiUserChat named"muc".

Iterator iter = muc.getOccupants();

Occupant opt =(Occupant)iter.next();

log.info("


opt.getNick()------ \n"+opt.getNick());

it throw a Exception:

java.util.NoSuchElementException

at java.util.AbstractList$Itr.next(Unknown Source)

at java.util.Collections$1.next(Unknown Source)

Hey doper,

When using iterator you always have to check if the iterator has a next element before requesting the next element. Send the #hasNext() message to the iterator before sending #next().

Regards,

– Gato

Thanks for you answer.