GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes illegal start of expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "illegal start of expression" Watch "illegal start of expression" New topic
Author

illegal start of expression

Aretha Clark
Greenhorn

Joined: Mar 07, 2008
Posts: 21
I seem to be getting this error message now after i figured out why it wasnt running.Any ideas or suggestions on how to correct this?

C:\jdk1.5.0_14\bin>javac Payroll.java
Payroll.java:51: illegal start of expression
public void static main(String[] args) {}
^
1 error

import java.util.Scanner;


public class Payroll {

public Payroll() {

{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );




// prompt for and input employee name
System.out.println( "Please enter the employee name:" );
String employeeName = input.nextLine(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hourly wage
System.out.println( "Please enter the employee hourly wage:" );
double hourlyWage = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hours worked
System.out.println( "Please enter the employee hours worked:" );
double hoursWorked = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line


System.out.println(); // outputs a blank line

System.out.println("Employee Name: " + employeeName);
System.out.println("Hourly Wage: " + hourlyWage);
System.out.println("Hours Worked: " + hourlyWage);

}

public void static main(String[] args) {}
new Payroll();

;
} // end method main


} // end class Payroll
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

Check your braces.... When you get to this line...



You are still defining your constructor. You are not allowed to define a method within a constructor.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Aretha Clark
Greenhorn

Joined: Mar 07, 2008
Posts: 21
If you dont mind can you explain this a lil further im very new to this and atm this one project has me pulling out










import java.util.Scanner;


public class Payroll {

public Payroll() {

{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );




// prompt for and input employee name
System.out.println( "Please enter the employee name:" );
String employeeName = input.nextLine(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hourly wage
System.out.println( "Please enter the employee hourly wage:" );
double hourlyWage = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hours worked
System.out.println( "Please enter the employee hours worked:" );
double hoursWorked = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line


System.out.println(); // outputs a blank line

System.out.println("Employee Name: " + employeeName);
System.out.println("Hourly Wage: " + hourlyWage);
System.out.println("Hours Worked: " + hourlyWage);



public void static main(String[] args){)
new Payroll();



// end method main


// end class Payroll
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

Braces must match. If you take your code and indent it according to braces, you will notice that what you mark as the end of main, is really the end of the constructor.

Henry

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

Also, the main method is defined within the constructor. The "new Payroll()" code which is probably supposed to be within the main() method, is actually not. It is also defined within the constructor -- after the main() method.


This indentation is probably *not* what you wanted. However, based on the braces, this is what the compiler interprets.

Henry
[ June 10, 2008: Message edited by: Henry Wong ]
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Hello Aretha,

You have made couple of mistakes.

1) Signature of main() method.

2) Braces are at improper location as henry pointed.
3) you are creating an object of Payroll class at improper place.

Always remember to indent your code, that can uncover many errors and enclose your code with CODE TAG so that other ranchers can understand your code hence the problem very easily.

Here is your modified code.Of course using CODE tag.

[ June 10, 2008: Message edited by: Vishal Pandya ]
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
And yes, you are printing 'hourlyWage' in case of 'hours worked'.
Aretha Clark
Greenhorn

Joined: Mar 07, 2008
Posts: 21
Thank you very much its almost sickening that the misplacement of brackets can turn into a nightmare
 
GeeCON Prague 2014
 
subject: illegal start of expression