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 5 of 5

Thread: Error Check Not Working

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

    Default Error Check Not Working

    Lines 268 - 322 in public void ActionPerformed(command "add")
    This part of my code checks if JTextFields name and last contain a digit, this is a check error that creates a JOptionPane to display the error to the user, which works fine.

    Problem:
    Within the same lines, I error check if the user entered a character within JTextFields ID, hRate, and hHour. In line 341, I start the method public String Error(), to find the value of String error and place the final value of all checked errors within the String Error. The String Error is displayed in the JOptionPane. In the method Error(), my program does not go through the if statements for ID, hRate, and hHour, once the NumberFormatException Occurs the program method does not continue (like a break). I can't fix this dilemma, please help.

    Project9_1():
    package Payroll;
     
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextField;
    import javax.swing.ListSelectionModel;
     
    public class Project9_1 extends JFrame implements ActionListener{
     
        // Employee Picture
        // Save Files
        // Check if First Name or Last Name has two subStrings
        // Check if JField still has invalid or any past Errors with boolean
        // Delete Account, store ID value to be used again
        // Prevent Save If Error Occurs
        // Create Read/Write Files store into EmployeeArray
        // Add JMenu - Settings - Credits - Save - Log(new large JFrame with JList to view 100 logs)
     
        JFrame second;
        JPanel Main, Confirm;
        JLabel nameL, lastL, typeL, hRateL, hHourL, payL, logL, IDL;
        JTextField name, last, hRate, hHour, pay, ID;
        JList log;
        DefaultListModel logM;
        JScrollPane logS;
        JButton enter, one, two, add, delete, edit, clear, save;
        JFrame f = new JFrame();
        Employee[] EmployeeArray = new Employee[100];
        int count = 0;
        int eType = 0;
        int eHour = 0;
        int eID = 0;
        int index = 0;
        double eRate = 0;
        String Error = "";
        String Test = "";
        boolean ErrorName = false;
        boolean ErrorLast = false;
        boolean ErrorRate = false;
        boolean ErrorHour = false;
        boolean ErrorID = false;
        boolean ErrorNameLast = false;
        boolean ErrorIDRepeat = false;
     
        public Project9_1() {
            this.setTitle("Payroll");
            this.add(Panel());
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.pack();
            this.setLocationRelativeTo(null);
            this.setVisible(true);
        }
     
        public JPanel Panel(){
            Main = new JPanel();
            Main.setPreferredSize(new Dimension(300,350));
            Main.setLayout(null);
     
            nameL = new JLabel("Name:");
            nameL.setForeground(Color.RED);
            nameL.setBounds(10, 10, 100, 30);
            Main.add(nameL);
     
            name = new JTextField();
            name.setBounds(10, 35, 100, 30);
            name.setEditable(true);
            name.requestFocus();
            Main.add(name);
     
            lastL = new JLabel("Last Name:");
            lastL.setForeground(Color.RED);
            lastL.setBounds(150, 10, 100, 30);
            Main.add(lastL);
     
            last = new JTextField();
            last.setEditable(true);
            last.setBounds(150, 35, 100, 30);
            last.requestFocus();
            Main.add(last);
     
            typeL = new JLabel("Type: " + eType);
            typeL.setForeground(Color.RED);
            typeL.setBounds(10, 65, 100, 30);
            Main.add(typeL);
     
            one = new JButton("Full");
            one.setBounds(10, 90, 55, 30);
            one.addActionListener(this);
            one.setActionCommand("one");
            Main.add(one);
     
            two = new JButton("Part");
            two.setBounds(70, 90, 60, 30);
            two.addActionListener(this);
            two.setActionCommand("two");
            Main.add(two);
     
            hRateL = new JLabel("Hourly Rate:");
            hRateL.setBounds(10, 120, 100, 30);
            hRateL.setForeground(Color.RED);
            Main.add(hRateL);
     
            hRate = new JTextField();
            hRate.setEditable(true);
            hRate.requestFocus();
            hRate.setBounds(10, 145, 100, 30);
            Main.add(hRate);
     
            hHourL = new JLabel("Hours Worked:");
            hHourL.setForeground(Color.RED);
            hHourL.setBounds(10, 170, 100, 30);
            Main.add(hHourL);
     
            hHour = new JTextField();
            hHour.requestFocus();
            hHour.setEditable(true);
            hHour.setBounds(10, 195, 100, 30);
            Main.add(hHour);
     
            IDL = new JLabel("Employee ID:");
            IDL.setBounds(10, 220, 100, 30);
            IDL.setForeground(Color.RED);
            Main.add(IDL);
     
            ID = new JTextField();
            ID.requestFocus();
            ID.setBounds(10, 245, 100, 30);
            Main.add(ID);
     
            payL = new JLabel("Pay:");
            payL.setBounds(10, 270, 100, 30);
            payL.setForeground(Color.RED);
            Main.add(payL);
     
            pay = new JTextField();
            pay.requestFocus();
            pay.setText("0");
            pay.setEditable(false);
            pay.setBounds(10, 295, 100, 30);
            Main.add(pay);
     
            logL = new JLabel("Log:");
            logL.setForeground(Color.RED);
            logL.setBounds(150, 65, 100, 30);
            Main.add(logL);
     
            logM = new DefaultListModel();
            // Read File
            // logM.addElement("");
            log = new JList(logM);
            log.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            log.setSelectedIndex(0);
            log.setVisibleRowCount(10);
            log.setBounds(150, 90, 100, 120);
            Main.add(log);
     
            logS = new JScrollPane(log);
            logS.setBounds(150, 90, 100, 90);
            Main.add(logS);
     
            add = new JButton("Add Log");
            add.addActionListener(this);
            add.setActionCommand("add");
            add.setBounds(150, 180, 100, 30);
            Main.add(add);
     
            delete = new JButton("Delete Log");
            delete.setBounds(150, 210, 100, 30);
            delete.addActionListener(this);
            delete.setActionCommand("delete");
            Main.add(delete);
     
            edit = new JButton("Select Log");
            edit.setBounds(150, 240, 100, 30);
            edit.addActionListener(this);
            edit.setActionCommand("edit");
            Main.add(edit);
     
            clear = new JButton("Clear");
            clear.setBounds(150, 270, 100, 30);
            clear.addActionListener(this);
            clear.setActionCommand("clear");
            Main.add(clear);
     
            save = new JButton("Save");
            save.setBounds(150, 300, 100, 30);
            save.addActionListener(this);
            save.setActionCommand("save");
            Main.add(save);
     
            return Main;
        }
     
        public String Pay(){
            String pay = "";
            double tax = 0;
            double payroll = 0;
     
            payroll = (EmployeeArray[index].getHours() * 52) * EmployeeArray[index].getRate();
            //JOptionPane.showMessageDialog(f, "Payroll: " + payroll);
            tax = payroll * .1;
            //JOptionPane.showMessageDialog(f, "Marginal Tax Rate: " + tax);
            payroll = payroll - tax;
            //JOptionPane.showMessageDialog(f, "Total: " + payroll);
     
            pay = Double.toString(payroll);
            return pay;
        }
     
        public JPanel Confirm(){
            Confirm = new JPanel();
            Main.setPreferredSize(new Dimension(100,100));
            Main.setLayout(null);
     
            JLabel info = new JLabel("Full Time or Part Time");
            info.setBounds(10, 10, 100, 30);
            info.setForeground(Color.RED);
            Confirm.add(info);
     
            JButton full = new JButton("Full Time");
            full.setBounds(10, 30, 100, 30);
            full.addActionListener(this);
            full.setActionCommand("full");
            Confirm.add(full);
     
            JButton part = new JButton("Part Time");
            part.setBounds(50, 30, 100, 30);
            part.addActionListener(this);
            part.setActionCommand("part");
            Confirm.add(part);
     
            return Confirm;
        }
     
        public void actionPerformed(java.awt.event.ActionEvent e){
            if(e.getActionCommand().equals("one")){
                eType = 1;
                typeL.setText("Type: " + eType);
            }
            if(e.getActionCommand().equals("two")){
                eType = 2;
                typeL.setText("Type: " + eType);
            }
            if(e.getActionCommand().equals("full")){
                eType = 1;
                typeL.setText("Type: " + eType);
                EmployeeArray[index].setType(eType);
                second.dispose();
            }
            if(e.getActionCommand().equals("part")){
                eType = 2;
                typeL.setText("Type: " + eType);
                EmployeeArray[index].setType(eType);
                second.dispose();
            }
            if(e.getActionCommand().equals("add")){
                try{
                    Test = name.getText();
                    for(int i = 0; i < Test.length(); ++i){
                        if(Character.isDigit(Test.charAt(i))){
                            ErrorName = true;
                            JOptionPane.showMessageDialog(f, "Error First Name: " + ErrorName);
                        }
                    }
                }catch(Exception ex){
                    ex.printStackTrace();
                }
                try{
                    Test = last.getText();
                    for(int i = 0; i < Test.length(); ++i){
                        if(Character.isDigit(Test.charAt(i))){
                            ErrorLast = true;
                            JOptionPane.showMessageDialog(f, "Error Last Name: " + ErrorLast);
                        }
                    }
                }catch(Exception ex1){
                    ex1.printStackTrace();
                }
                try{
                    eHour = Integer.parseInt(hHour.getText());
                }catch(NumberFormatException ex2){
                    ex2.printStackTrace();
                    ErrorHour = true;
                    JOptionPane.showMessageDialog(f, "Error Hour: " + ErrorHour);
                }
                try{
                    eRate = Double.parseDouble(hRate.getText());
                }catch(NumberFormatException ex3){
                    ex3.printStackTrace();
                    ErrorRate = true;
                    JOptionPane.showMessageDialog(f, "Error Rate: " + ErrorRate);
                }
                try{
                    eID = Integer.parseInt(ID.getText());
                }catch(NumberFormatException ex4){
                    ex4.printStackTrace();
                    ErrorID = true;
                    JOptionPane.showMessageDialog(f, "Error ID: " + ErrorID);
                }
                if(count > 0){
                    for(int i = 0; i < count; ++i){
                        if(name.getText().equals(EmployeeArray[i].getFirstName()) && last.getText().equals(EmployeeArray[i].getLastName())){
                            ErrorNameLast = true;
                            JOptionPane.showMessageDialog(f, "Error Name Repeat: " + ErrorNameLast);
                        }
                        if(Integer.parseInt(ID.getText()) == EmployeeArray[i].getID()){
                            ErrorIDRepeat = true;
                            JOptionPane.showMessageDialog(f, "Error ID Repeat: " + ErrorIDRepeat);
                        }
                    }
                }
     
                eHour = Integer.parseInt(hHour.getText());
                eRate = Double.parseDouble(hRate.getText());
                eID = Integer.parseInt(ID.getText());
                if(!hRate.getText().equals(null) && !hRate.getText().equals("") && !hHour.getText().equals(null) && !hHour.getText().equals("") && !ID.getText().equals(null) && !ID.getText().equals("") && !ID.getText().equals("Exists") && !last.getText().equals("Exists") && !name.getText().equals("Exists") && !ID.getText().equals("Full") && !ID.getText().equals("Invalid") && !hRate.getText().equals("Invalid") && !hHour.getText().equals("Invalid") && !name.getText().equals("") && !last.getText().equals("") && !name.getText().equals("Invalid") && !last.getText().equals("Invalid") && !name.getText().equals(null) && !last.getText().equals(null) && eType != 0 && eRate >= 6.75 && eRate <= 30.5 && eHour >= 1 && eHour <= 60 && ErrorName == false && ErrorLast == false && ErrorHour == false && ErrorRate == false && ErrorID == false && eID <= 100 && eID > 0 && count < 100 && ErrorNameLast == false && ErrorIDRepeat == false){
                    EmployeeArray[count] = new Employee(name.getText(), last.getText(), eType, eRate, eHour, eID);
                    pay.setText(Pay());
                    logM.addElement(EmployeeArray[count].getFirstName() + " " + EmployeeArray[count].getLastName() + " " + EmployeeArray[count].getID());
                    eType = 0;
                    typeL.setText("Type: " + eType);
                    eRate = 0;
                    eHour = 0;
                    ++count;
                    delete.setEnabled(true);
                    edit.setEnabled(true);
                    // Write Into File
                }else{
                    // JOptionPane not opening at all for ErrorHour to ErrorID or the Blank Fields
                    Error = "Error: Type(How To Fix)" + Error();
     
                    JOptionPane.showMessageDialog(f, Error);
                    Error = "";
                    ErrorName = false;
                    ErrorLast = false;
                    ErrorHour = false;
                    ErrorRate = false;
                    ErrorID = false;
                    ErrorNameLast = false;
                    ErrorIDRepeat = false;
                }
            }
            if(e.getActionCommand().equals("delete")){
                // Store Deleted count into an array to be used again
                int index = 0;
                index = log.getSelectedIndex();
                logM.remove(index);
     
                int size = logM.getSize();
     
                if (size == 0) {
                    delete.setEnabled(false);
                    edit.setEnabled(false);
                } else {
                    if (index == logM.getSize()) {
                        index--;
                    }
     
                    log.setSelectedIndex(index);
                    log.ensureIndexIsVisible(index);
                }
                --count;
            }
            if(e.getActionCommand().equals("edit")){
                int index = 0;
                for(int i = 0; i <= count; ++i){
                    Test = EmployeeArray[i].getFirstName() + " " + EmployeeArray[i].getLastName() + " " + EmployeeArray[i].getID();
                    if(Test.equals(log.getSelectedValue())){
                        index = i;
                        name.setText(EmployeeArray[i].getFirstName());
                        last.setText(EmployeeArray[i].getLastName());
                        hRate.setText(Double.toString(EmployeeArray[i].getRate()));
                        hHour.setText(Integer.toString(EmployeeArray[i].getHours()));
                        eType = EmployeeArray[i].getType();
                        typeL.setText("Type: " + eType);
                        ID.setText(Integer.toString(EmployeeArray[i].getID()));
                        pay.setText(Pay());
                    }
                }
            }
            if(e.getActionCommand().equals("clear")){
                name.setText("");
                last.setText("");
                eType = 0;
                typeL.setText("Type: " + eType);
                hHour.setText("");
                hRate.setText("");
                ID.setText("");
                pay.setText("");
            }
            if(e.getActionCommand().equals("save")){
                EmployeeArray[index].setFirstname(name.getText());
                EmployeeArray[index].setLastName(last.getText());
                EmployeeArray[index].setHours(Integer.parseInt(hHour.getText()));
                EmployeeArray[index].setRate(Double.parseDouble(hRate.getText()));
                EmployeeArray[index].setID(Integer.parseInt(ID.getText()));
                if(eType == 0){
                    second = new JFrame();
                    second.setTitle("Confirm Type");
                    second.add(Confirm());
                    second.pack();
                    second.setLocationRelativeTo(null);
                    second.setVisible(true);
                }else{
                    EmployeeArray[index].setType(eType);
                }
            }
        }
     
        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")){
                JOptionPane.showMessageDialog(f, "Checked 8");
                error = error + "\nError: Previous Invalid Error or" +
                        "\nInvalid Input Not Accepted(Hours Worked)";
            }
            if(hRate.getText().equals("Invalid")){
                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;
        }
     
        public static void main(String[] args){
            new Project9_1();
        }
    }

    Employee():

    package Payroll;
     
    public class Employee {
     
        private String firstName;
        private String lastName;
        private int type;
        private double rate;
        private int hours;
        private int ID;
     
        public Employee() {
            firstName = null;
            lastName = null;
            type = 0;
            rate = 0;
            hours = 0;
            ID = 0;
        }
     
        public Employee(String fName, String lName, int t, double r, int h, int i){
            firstName = fName;
            lastName = lName;
            type = t;
            rate = r;
            hours = h;
            ID = i;
        }
     
        public Employee(Employee e){
            this(e.firstName, e.lastName, e.type, e.rate, e.hours, e.ID);
        }
     
        public void setFirstname(String fName){
            firstName = fName;
        }
        public String getFirstName(){
            return firstName;
        }
     
        public void setLastName(String lName){
            lastName = lName;
        }
        public String getLastName(){
            return lastName;
        }
     
        public void setType(int t){
            type = t;
        }
        public int getType(){
            return type;
        }
     
        public void setRate(double r){
            rate = r;
        }
        public double getRate(){
            return rate;
        }
     
        public void setHours(int h){
            hours = h;
        }
        public int getHours(){
            return hours;
        }
     
        public void setID(int i){
            ID = i;
        }
        public int getID(){
            return ID;
        }
    }


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Error Check Not Working

    Hmm... I'm finding this hard to decipher. Can you post the error message and the lines of code directly associated with and near to where the exception is thrown? There aren't line numbers on the code snippets above, and I don't really want to count to line 268...
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

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

    Default Re: Error Check Not Working

    Sorry,

    I first go through a series of try and catch exceptions to check if there are errors in my JTextFields because ID, hHour, hRate can only contain digits and name and last Fields can only contain characters. The name and last error checks works, the JOptionPane pop up is executed and tells the user of their mistake. If ErrorID, ErrorRate, and ErrorHour is true, it will still not go through the if statement, the value of Error is not changed, the text is not set, and the JOptionPane does not open. Its like once the NumberFormatException occurs, a break happens and exits the method.

    Try and catch exception Error Checks:
    if(e.getActionCommand().equals("add")){
                try{
                    Test = name.getText();
                    for(int i = 0; i < Test.length(); ++i){
                        if(Character.isDigit(Test.charAt(i))){
                            ErrorName = true;
                            JOptionPane.showMessageDialog(f, "Error First Name: " + ErrorName);
                        }
                    }
                }catch(Exception ex){
                    ex.printStackTrace();
                }
                try{
                    Test = last.getText();
                    for(int i = 0; i < Test.length(); ++i){
                        if(Character.isDigit(Test.charAt(i))){
                            ErrorLast = true;
                            JOptionPane.showMessageDialog(f, "Error Last Name: " + ErrorLast);
                        }
                    }
                }catch(Exception ex1){
                    ex1.printStackTrace();
                }
                try{
                    eHour = Integer.parseInt(hHour.getText());
                }catch(NumberFormatException ex2){
                    ex2.printStackTrace();
                    ErrorHour = true;
                    JOptionPane.showMessageDialog(f, "Error Hour: " + ErrorHour);
                }
                try{
                    eRate = Double.parseDouble(hRate.getText());
                }catch(NumberFormatException ex3){
                    ex3.printStackTrace();
                    ErrorRate = true;
                    JOptionPane.showMessageDialog(f, "Error Rate: " + ErrorRate);
                }
                try{
                    eID = Integer.parseInt(ID.getText());
                }catch(NumberFormatException ex4){
                    ex4.printStackTrace();
                    ErrorID = true;
                    JOptionPane.showMessageDialog(f, "Error ID: " + ErrorID);
                }
                if(count > 0){
                    for(int i = 0; i < count; ++i){
                        if(name.getText().equals(EmployeeArray[i].getFirstName()) && last.getText().equals(EmployeeArray[i].getLastName())){
                            ErrorNameLast = true;
                            JOptionPane.showMessageDialog(f, "Error Name Repeat: " + ErrorNameLast);
                        }
                        if(Integer.parseInt(ID.getText()) == EmployeeArray[i].getID()){
                            ErrorIDRepeat = true;
                            JOptionPane.showMessageDialog(f, "Error ID Repeat: " + ErrorIDRepeat);
                        }
                    }
                }
     
                eHour = Integer.parseInt(hHour.getText());
                eRate = Double.parseDouble(hRate.getText());
                eID = Integer.parseInt(ID.getText());
                if(!hRate.getText().equals(null) && !hRate.getText().equals("") && !hHour.getText().equals(null) && !hHour.getText().equals("") && !ID.getText().equals(null) && !ID.getText().equals("") && !ID.getText().equals("Exists") && !last.getText().equals("Exists") && !name.getText().equals("Exists") && !ID.getText().equals("Full") && !ID.getText().equals("Invalid") && !hRate.getText().equals("Invalid") && !hHour.getText().equals("Invalid") && !name.getText().equals("") && !last.getText().equals("") && !name.getText().equals("Invalid") && !last.getText().equals("Invalid") && !name.getText().equals(null) && !last.getText().equals(null) && eType != 0 && eRate >= 6.75 && eRate <= 30.5 && eHour >= 1 && eHour <= 60 && ErrorName == false && ErrorLast == false && ErrorHour == false && ErrorRate == false && ErrorID == false && eID <= 100 && eID > 0 && count < 100 && ErrorNameLast == false && ErrorIDRepeat == false){
                    EmployeeArray[count] = new Employee(name.getText(), last.getText(), eType, eRate, eHour, eID);
                    pay.setText(Pay());
                    logM.addElement(EmployeeArray[count].getFirstName() + " " + EmployeeArray[count].getLastName() + " " + EmployeeArray[count].getID());
                    eType = 0;
                    typeL.setText("Type: " + eType);
                    eRate = 0;
                    eHour = 0;
                    ++count;
                    delete.setEnabled(true);
                    edit.setEnabled(true);
                    // Write Into File
                }else{
                    // JOptionPane not opening at all for ErrorHour to ErrorID or the Blank Fields
                    Error = "Error: Type(How To Fix)" + Error();
     
                    JOptionPane.showMessageDialog(f, Error);
                    Error = "";
                    ErrorName = false;
                    ErrorLast = false;
                    ErrorHour = false;
                    ErrorRate = false;
                    ErrorID = false;
                    ErrorNameLast = false;
                    ErrorIDRepeat = false;
                }
            }

    Error String Method:
    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")){
                JOptionPane.showMessageDialog(f, "Checked 8");
                error = error + "\nError: Previous Invalid Error or" +
                        "\nInvalid Input Not Accepted(Hours Worked)";
            }
            if(hRate.getText().equals("Invalid")){
                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;
        }

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

    Default Re: Error Check Not Working

    The JOptionPane.showMessageDialog(f, "Error First Name: " + ErrorName); in the try and catch piece of code is to only check for the value of the boolean, the check error pop up that is not working is the one in the else statement, where I start the Error() String method.

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

    Default Re: Error Check Not Working

    I have a theory on how to solve the problem, I will use several switch statements to help java process each if statement.

Similar Threads

  1. ...differ in length error; homework starter code not working.
    By mwebb in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 10th, 2011, 12:20 PM
  2. logic error somewhere.. working with try & catch, simple array.. please help
    By basketball8533 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 9th, 2010, 12:40 PM
  3. how to check the value
    By javaking in forum Java Servlet
    Replies: 2
    Last Post: July 22nd, 2010, 06:56 AM
  4. Collision Check Error
    By Josh Yaxley in forum What's Wrong With My Code?
    Replies: 19
    Last Post: July 12th, 2010, 02:12 PM
  5. Replies: 4
    Last Post: January 27th, 2009, 12:03 AM