mercredi 28 avril 2021

Java program "entering" if statement despite not meeting condition [duplicate]

I have what would be a simple if statement to check if two strings are null.

 if (airlineID == "null" && airportID == "null"){
        JOptionPane.showMessageDialog(null, "Airline and airport do not exist or are incorrect");
}
else if (airlineID == "null") {
        JOptionPane.showMessageDialog(null, "Airline incorrect or does not exist");
}
else if (airportID == "null") {
        JOptionPane.showMessageDialog(null, "Airport code incorrect or does not exist" );
}
else if (airlineID != "null" && airportID != "null"){ // 4.1 If they both exist, then proceed
        // Do stuff
}

However, no matter the actual contents of airportID or airlineID, it always enters the last statement.

Here is a picture from the debugger showing the statement enter image description here

The blue line is where the program is currently at, as you can see it's entered the last if statement despite not meeting the requirements.

Here's a picture from the variables' values to confirm

enter image description here

Note: I have "null" as a string because the server sends the reply back as a string.

Aucun commentaire:

Enregistrer un commentaire