Java Reference
In-Depth Information
javac: Illegal Start of Expression
This is a generic error message if we didn't tidy up an expression as we should
have and the compiler isn't ready to start a new expression yet—for instance,
if I leave off the closing brace at the end of a function:
public void disable() {
log.info( "Stopping." );
Again I'll get a bunch of errors, starting at the point of the missing brace and
continuing way past it into the rest of the file:
src/helloworld/HelloWorld.java:21: illegal start of expression
public void helloCommand(MessageReceiver caller, String[] parameters)
^
src/helloworld/HelloWorld.java:21: ';' expected
public void helloCommand(MessageReceiver caller, String[] parameters)
^
src/helloworld/HelloWorld.java:21: ';' expected
public void helloCommand(MessageReceiver caller, String[] parameters)
^
src/helloworld/HelloWorld.java:21: not a statement
Just remember that “illegal start” really means “didn't finish properly.”
javac: Class Is Public, Should Be Declared in a File Named…
In my HelloWorld.java , I get creative and start to add another class declaration
at the end of the file:
public class TooMany {
// ...
}
This generates a very descriptive error message:
src/helloworld/HelloWorld.java:32: class TooMany is public ,
should be declared in a file named TooMany.java
public class TooMany {
Remember that every public class must be in a separate file that is named
for the class, in a directory named for the package.
However, you can declare a private class inside your public class within the
same file. This can sometimes be helpful for small helper classes.
 
 
Search WWH ::




Custom Search