Java Reference
In-Depth Information
Continued from previous page
location: class java.io.PrintStream
System.out.pruntln("Hello, world!");
∧
1 error
The first line of this output indicates that the error occurs in the file
Hello.java
on line 3 and that the error is that the compiler cannot find a symbol. The second
line indicates that the symbol it can't find is a method called
pruntln
. That's
because there is no such method; the method is called
println.
The error mes-
sage can take slightly different forms depending on what you have misspelled.
For example, you might forget to capitalize the word
System:
system.out.println("Hello, world!");
You will get the following error message:
Hello.java:3: package system does not exist
system.out.println("Hello, world!");
∧
1 error
Again, the first line indicates that the error occurs in line 3 of the file
Hello.java.
The error message is slightly different here, though, indicating
that it can't find a package called
system
. The second and third lines of this
error message include the original line of code with an arrow (caret) pointing to
where the compiler got confused. The compiler errors are not always very clear,
but if you pay attention to where the arrow is pointing, you'll have a pretty good
sense of where the error occurs.
If you still can't figure out the error, try looking at the error's line number and
comparing the contents of that line with similar lines in other programs. You can also
ask someone else, such as an instructor or lab assistant, to examine your program.
Common Programming Error
Forgetting a Semicolon
All Java statements must end with semicolons, but it's easy to forget to put a
semicolon at the end of a statement, as in the following program:
1
public class
MissingSemicolon {
2
public static void
main(String[] args) {
3 System.out.println("A rose by any other name")
Continued on next page
Search WWH ::
Custom Search