Issue
I am very confused as to why this is happening. When I run this code and leave the txtFirstName field blank, it returns true even though it clearly shouldn't.
@FXML
private void signUp(ActionEvent event) {
if (txtFirstName.getText() != null) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("IT WORKS");
alert.setHeaderText("IT WORKS!");
alert.setContentText("IT WORKS!!!!!");
alert.showAndWait();
} else {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Warning");
alert.setHeaderText("There was a problem creating your account");
alert.setContentText("Please fill out every field with the minimum requirements!");
alert.showAndWait();
}
}
When I do type a value into the First Name field, I get the else statement when I should be getting the if statement... Am I insane or is this backwards?
Solution
Assuming your First Name field is a String, you can use
txtFirstName.getText().isEmpty();
Hope this solves your question!
Answered By - TheXDShrimp