Not Reaching If Statement
Boolean ErrorHour value is true because I checked using the JOptionPane message box.
Then I run this method, but when it runs to the if statement ErrorHour equals true, is doesn't work, the message box does not open, the String value of error does not change, ErrorRate and Error ID does the same thing:
Code :
public String Error(){
String error = "";
if(name.getText().equals("") || name.getText().equals(null)){
JOptionPane.showMessageDialog(f, "Checked 1");
error = error + "Error: Invalid Name(Blank)";
name.setText("Invalid");
}
if(last.getText().equals("") || last.getText().equals(null)){
JOptionPane.showMessageDialog(f, "Checked 2");
error = error + "\nError: Invalid Last Name(Blank)";
last.setText("Invalid");
}
if(hHour.getText().equals("") || hHour.getText().equals(null)){
JOptionPane.showMessageDialog(f, "Checked 3");
error = error + "\nError: Invalid Work Hours(Blank)";
hHour.setText("Invalid");
}
if(hRate.getText().equals("") || hRate.getText().equals(null)){
JOptionPane.showMessageDialog(f, "Checked 4");
error = error + "\nError: Invalid Hourly Rate(Blank)";
hRate.setText("Invalid");
}
if(ID.getText().equals("") || ID.getText().equals(null)){
JOptionPane.showMessageDialog(f, "Checked 5");
error = error + "\nError: Invalid Employee ID(Blank)";
ID.setText("Invalid");
}
if(name.getText().equals("Invalid") || name.getText().equals("Exists")){
JOptionPane.showMessageDialog(f, "Checked 6");
error = error + "\nError: Previous Invalid/Existing Error or" +
"\nInvalid/Existing Input Not Accepted(Name)";
}
if(last.getText().equals("Invalid") || last.getText().equals("Exists")){
JOptionPane.showMessageDialog(f, "Checked 7");
error = error + "\nError: Previous Invalid/Existing Error or" +
"\nInvalid/Existing Input Not Accepted(Last)";
}
if(hHour.getText().equals("Invalid") && ErrorHour == false){
JOptionPane.showMessageDialog(f, "Checked 8");
error = error + "\nError: Previous Invalid Error or" +
"\nInvalid Input Not Accepted(Hours Worked)";
}
if(hRate.getText().equals("Invalid") && ErrorRate == false){
JOptionPane.showMessageDialog(f, "Checked 9");
error = error + "\nError: Previous Invalid Error or" +
"\nInvalid Input Not Accepted(Hourly Rate)";
}
if(ID.getText().equals("Full") || ID.getText().equals("Exists") || ID.getText().equals("Invalid")){
JOptionPane.showMessageDialog(f, "Checked 10");
error = error + "\nError: Previous Invalid/Existing/Full Error or" +
"\nInvalid/Existing/Full Input Not Accepted(ID)";
}
if(eType == 0){
JOptionPane.showMessageDialog(f, "Checked 11");
error = error + "\nError: Type Required(Button Full or Part)";
}
if(eHour < 1 || eHour > 60){
JOptionPane.showMessageDialog(f, "Checked 12");
error = error + "\nError: Invalid Working Hours(1 - 60)";
hHour.setText("Invalid");
}
if(eRate < 6.75 || eRate > 30.5){
JOptionPane.showMessageDialog(f, "Checked 13");
error = error + "\nError: Invalid Hourly Rate(6.75 - 30.50)";
hRate.setText("Invalid");
}
if(eID > 100 || eID < 1){
JOptionPane.showMessageDialog(f, "Checked 14");
error = error + "\nError: Invalid ID Value(1-100)";
ID.setText("Invalid");
}
if(ErrorName == true){//Works
JOptionPane.showMessageDialog(f, "Checked 15");
error = error + "\nError: First Name Input(A-Z)";
name.setText("Invalid");
}
if(ErrorLast == true){//Works
JOptionPane.showMessageDialog(f, "Checked 16");
error = error + "\nError: Last Name Input(A-Z)";
last.setText("Invalid");
}
if(ErrorHour == true){
JOptionPane.showMessageDialog(f, "Checked 17");
error = error + "\nError: Working Hour Input(Numberical)";
hHour.setText("Invalid");
}
if(ErrorRate == true){
JOptionPane.showMessageDialog(f, "Checked 18");
error = error + "\nError: Hourly Rate Input(Numberical)";
hRate.setText("Invalid");
}
if(ErrorID == true){
JOptionPane.showMessageDialog(f, "Checked 19");
error = error + "\nError: Employee ID Input(Numberical)";
ID.setText("Invalid");
}
if(ErrorNameLast == true){
JOptionPane.showMessageDialog(f, "Checked 20");
error = error + "\nError: First and Last Name Exists";
name.setText("Exists");
last.setText("Exists");
}
if(ErrorIDRepeat == true){
JOptionPane.showMessageDialog(f, "Checked 21");
error = error + "\nError: Employee ID In Use";
ID.setText("Exists");
}
if(count == 99){
JOptionPane.showMessageDialog(f, "Checked 22");
error = error + "\nError: Employee List Is Full(Delete)";
ID.setText("Full");
}
return error;
}
Re: Not Reaching If Statement
You haven't really provided the correct code for us to be able to help you. If you want help, you should provide an SSCCE that demonstrates the problem. Please note that this is NOT your entire program, and in fact should probably be less code than you've already posted, just enough for us to understand the actual values you're using to result in the behavior. Chances are, in the process of boiling your problem down to an SSCCE, you'll figure it out on your own!