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

Thread: illegal start of expression

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default illegal start of expression

    I have been reading and reading about this error and I cannot figure out why my app is throwing this error. Line 29 private JTextField fnameTF, lnameTF, hoursTF, hrateTF, idTF, weeknumTF, netPayTF;

    private JTextField fnameTF, lnameTF, hoursTF, hrateTF, idTF, weeknumTF, netPayTF;
     private  JLabel fnameL, lnameL, hoursL, hrateL, idL, weeknumL, netPayL;
    //right column of GUI component for entering information in the fields
    private JButton calculateB, resetB, addB, exitB; //Buttons listed on GUI component
    private CalculateButtonHandler cbHandler;
    private ResetButtonHandler rbHandler;
    private AddButtonHandler abHandler;
    private ExitButtonHandler ebHandler;
     
    //methods objects for submit buttons on GUI
    private static final int WIDTH = 400;
    private static final int HEIGHT = 300;
    //height and width of GUI component}
    public PayrollCalculator()
     
       {
    //Create the seven labels, right justified
    fnameL = new JLabel("Enter First Name: ",SwingConstants.RIGHT);
    lnameL = new JLabel("Enter Last Name: ",SwingConstants.RIGHT);
    hoursL = new JLabel("Enter Hours Worked: ", SwingConstants.RIGHT);
    hrateL = new JLabel("Enter Hourly Rate: ", SwingConstants.RIGHT);
    idL = new JLabel("Enter Employee ID: ", SwingConstants.RIGHT);
    weeknumL = new JLabel("Enter Week Number: ", SwingConstants.RIGHT);
    netPayL = new JLabel("Calculated Net Pay: ", SwingConstants.RIGHT);
    //Create the seven text fields, ten characters in length
    fnameTF = new JTextField(20);
    lnameTF = new JTextField(20);
    hoursTF = new JTextField(20);
    hrateTF = new JTextField(20);
    idTF = new JTextField(20);
    weeknumTF = new JTextField(20);
    netPayTF = new JTextField(20);
    //Create Calculate Button to determine and show calculated net pay
    calculateB = new JButton("Calculate");
    cbHandler = new CalculateButtonHandler();
    calculateB.addActionListener(cbHandler);
    //Create Reset Button to clear text in field and re-enter information
    resetB = new JButton("Clear");
    rbHandler = new ResetButtonHandler();
    resetB.addActionListener(rbHandler);
    //Create Add to File Button which will print all informatio to a file
    addB = new JButton("Add to File");
    abHandler = new AddButtonHandler();
    addB.addActionListener(abHandler);
    //Create Exit Button closes the GUI screen when complete
    exitB = new JButton("Exit");
    ebHandler = new ExitButtonHandler();
    exitB.addActionListener(ebHandler);
    //Set the title of the window
    setTitle("Calculate a Pay Check");
    //Get the container
    Container pane = getContentPane();
    //Set the layout of rows and columns
    pane.setLayout(new GridLayout(9, 2));
    //Place the components in the pane
    pane.add(fnameL);
    pane.add(fnameTF);
    pane.add(lnameL);
    pane.add(lnameTF);
    pane.add(hoursL);
    pane.add(hoursTF);
    pane.add(hrateL);
    pane.add(hrateTF);
    pane.add(idL);
    pane.add(idTF);
    pane.add(weeknumL);
    pane.add(weeknumTF);
    pane.add(netPayL);
    pane.add(netPayTF);
    pane.add(calculateB);
    pane.add(addB);
    pane.add(resetB);
    pane.add(exitB);
    //Set the size of the window and display it
    setSize(WIDTH, HEIGHT);
    setVisible(true);
    //setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
     
        private void setTitle(String calculate_a_Pay_Check) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
        private Container getContentPane() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
        private void setSize(int WIDTH, int HEIGHT) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
        private void setVisible(boolean b) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    private class CalculateButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    double hours, rate, netPay;
    //calculate pay and display in caluculated net pay
    hours = Double.parseDouble(hoursTF.getText());
    rate = Double.parseDouble(hrateTF.getText());
    netPay = hours * rate;
    netPayTF.setText("" + netPay);
    }
    }
    private class ResetButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    //resets JTextFields
    fnameTF.setText("");
    lnameTF.setText("");
    hoursTF.setText("");
    hrateTF.setText("");
    idTF.setText("");
    weeknumTF.setText("");
    netPayTF.setText("");
    }
    }
    //Add to File code
    private class AddButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    // Stream to write file
    FileOutputStream fout;	
    try
    {
    // Open an output stream
    fout = new FileOutputStream ("myfile.txt");
    // Print a line of text
    new PrintStream(fout).println ("hello world!" + fnameTF.getText());
    // Close the output stream
    fout.close();	
    }
    catch (IOException f)
    {
    System.err.println ("Unable to write to file");
    System.exit(-1);
    }
    }
    }
    private class ExitButtonHandler implements ActionListener
    {
    @Override
    public void actionPerformed(ActionEvent e)
    {
    System.exit(0);
    }
    }
     
    {
    PayrollCalculator rectObject = new PayrollCalculator();
     
        }
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,351
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: illegal start of expression

    You need to post the statements before where the error happens.
    The statements after the error are not very important.

    Also post the full text of the error message that shows the statement with the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    JoeSmo (May 6th, 2013)

  4. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: illegal start of expression

    highlighted error before run "illegal start of expression" ----- Line 29

    Error thrown after run
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - illegal start of expression
    at payrollcalculator.PayrollCalculator.main(PayrollCa lculator.java:29)
    Java Result: 1

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,351
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: illegal start of expression

    Can you post the source code from line 1 through line 29?
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    JoeSmo (May 6th, 2013)

  7. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: illegal start of expression

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package payrollcalculator;
     
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
     
    /**
     *
     * @author *********
     */
    public class PayrollCalculator {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
     
     
    private JTextField fnameTF, lnameTF, hoursTF, hrateTF, idTF, weeknumTF, netPayTF;

    error will no be on line 23 imported java.awt.* library along with the java. io.* library

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,351
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: illegal start of expression

    Local variables can't be private and don't need to be, because they only exist when the method is executing.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    JoeSmo (May 6th, 2013)

  10. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: illegal start of expression

    Okay what should I change the variables to?

  11. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,351
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: illegal start of expression

    Remove the private or move the statement outside of the method.
    If you don't understand my answer, don't ignore it, ask a question.

  12. The Following User Says Thank You to Norm For This Useful Post:

    JoeSmo (May 6th, 2013)

  13. #9
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: illegal start of expression

    alrighty thank you Norm

Similar Threads

  1. Illegal start of expression
    By bad_newbie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 16th, 2013, 08:57 PM
  2. Illegal start of expression!
    By NoobOfTheMonth in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 11th, 2013, 09:53 PM
  3. Help With illegal start of expression
    By inshal in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 9th, 2013, 01:20 PM
  4. need help with illegal start of expression
    By inshal in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 9th, 2013, 11:25 AM
  5. Help With illegal start of expression
    By RaceRed in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 7th, 2013, 09:02 PM