Step 5 of 5
Reading compiler errors
Before a program runs, the compiler reads all of it. If something isn't valid Java, it stops and prints an error instead, and nothing runs. Errors are normal: they're the compiler pointing at the exact spot it didn't understand. Here is a program with one character missing:
public class Main {
public static void main(String[] args) {
System.out.println("Hello")
}
}
Main.java:3: error: ';' expected
System.out.println("Hello")
^
1 errorRead it piece by piece:
Main.java:3is the file and the line number: line 3.error: ';' expectedsays what went wrong: Java expected a semicolon.- The next line repeats the code, and the
^below it points at the exact position, here the end of the line where the;belongs. 1 errorcounts the errors. Fix the first one first: one mistake sometimes confuses the compiler into reporting more lines after it.
On this site each error also gets a plain-English explanation under it, and the editor marks the line.
A few words to know
- A statement is one instruction. The ones in this module each end with a semicolon.
- The text inside the parentheses of
println( ... )is the parameter: the value the method works with. - A typo in a name gives a
cannot find symbolerror. For exampleSystem.out.printn("Hi");makes the compiler report that there is no methodprintn.