I am trying to remove data from a double linked list using the remove method using a iterator and I keep getting a null pointer exception.
This is what I have
System.out.print("Enter student ID: ");
String studentID2 = in.next();
Iterator<Student> iter = students.iterator();
while (iter.hasNext()) {
Student stu = (Student) iter.next();
if(stu.getStudentID().equals(studentID2)){
iter.remove();
}
}
Says the error is in my remove method
public void remove() {
lastItemRet = lastItemRet.prev;
lastItemRet.next = nextItem; The error is on this line.
nextItem.prev = lastItemRet;
}