Sto provando a ripetere un elenco utilizzando l'iteratore sul mio elenco di registri. L'obiettivo è cercare un log che contenga lo stesso numero di telefono, tipo e data del nuovo registrojava.util.NoSuchElementException using iterator in java
Tuttavia, ottengo un java.util.NoSuchElementException nella mia istruzione condizionale. Qualcuno sa che cosa potrebbe causare il problema?
Il mio codice
public void addLog(String phonenumber, String type, long date, int incoming, int outgoing)
{
//Check if log exists or else create it.
Log newLog = new Log(phonenumber, type, date, incoming, outgoing);
//Log exists
Boolean notExist = false;
//Iterator loop
Iterator<Log> iterator = logs.iterator();
while (iterator.hasNext())
{
//This is where get the exception
if (iterator.next().getPhonenumber() == phonenumber && iterator.next().getType() == type && iterator.next().getDate() == date)
{
updateLog(newLog, iterator.next().getId());
}
else
{
notExist = true;
}
}
if (notExist)
{
logs.add(newLog);
}
}