lundi 26 janvier 2015

The 'if' Statement is Redundant

I am trying to code a validation system to validate if the user has inputted in the fields required. I seem to be getting an error "The 'if' Statement is Redundant" can someone help me fix this problem? Or maybe come up with a better way of validating the fields to check if the fields are not empty.



String messageId = messageIdText.getText();
String subject = subjectText.getText();
String recipient = recipientText.getText();
String message = messageArea.getText();
boolean allFieldsCheck = false;

if (messageId.equals("") ){
allFieldsCheck = false;
} else {
allFieldsCheck = true;
}
if (subject.equals("") ){
allFieldsCheck = false;
} else {
allFieldsCheck = true;
}
if (recipient.equals("") ){
allFieldsCheck = false;
} else {
allFieldsCheck = true;
}
if (message.equals("") ){
allFieldsCheck = false;
} else {
allFieldsCheck = true;
}

Aucun commentaire:

Enregistrer un commentaire