Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Not Reaching If Statement

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default 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:

    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;
        }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. not a statement?
    By frozen java in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 23rd, 2011, 08:57 PM
  2. If statement help
    By Legion of Daughters in forum Loops & Control Statements
    Replies: 12
    Last Post: September 6th, 2011, 08:25 AM
  3. If Statement
    By Shyamz1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 26th, 2010, 12:57 PM
  4. If-Else Statement help
    By SnowCrashed in forum Loops & Control Statements
    Replies: 5
    Last Post: February 9th, 2010, 07:57 PM
  5. If statement
    By Dave in forum Loops & Control Statements
    Replies: 2
    Last Post: August 27th, 2009, 10:11 AM