I’m having a big issue with some nested while loops I have in my java program. From what I have debugged my code checks the second while loops statement once, then exits the loop forever. I have no clue why this is happening so I will post the code here:
while (current != null) {
if(id == current.getMovie().getId()) {
movieExists = true;
movie = current;
while (checkCurrent == movie) {
showingPointer = checkCurrent.getMovie().getLinkHead();
while (showingPointer != null) {
if (cal.compareTo(showingPointer.getShowing().getShowingCalendar()) == 0) {
return false;
}
showingPointer = showingPointer.getNext();
}
checkCurrent = checkCurrent.getNext();
}
}
current = current.getNext();
}
This statement
compares object reference and always false . This is not the way to compare two instances
you might want to change the code to compare values something like
Or have a equals() implemented to compare.
More on Equals