Following is a method that is iterating over a list:
@Override
public void DataRowMapper(List<?> list) {
Iterator<UserModel> i = (Iterator<UserModel>) list.iterator();
while (i.hasNext()) {
this.setUserID(i.next().getUserID());
this.setUserName(i.next().getUserName());
}
Now the problem is that when I run the debugger I see that i.hasNext() is having the correct values but still I keep getting NoElementException. Another surprising thing I have seen is that previously I was able to get the UserID printed on Console but just the UserID, rest of it was null but soon after I started getting this error. There is no issue at all with the database. I am 100% convinced that I am getting the right results because I see it in the debugger but for some reason I cant get past through this error in the normal mode. Class UserModel is a simple POJO.
you are calling i.next twice in the loop which will move the record pointer to next element.get the reference to element with a single call to i.next.
so it should be like