Common errors
Compile errors such as “cannot find symbol” and “incompatible types”, and exceptions such as NullPointerException.
Runs in Zerethon IDE · Java 25
Official Java documentation ↗
Compile errors come from javac and name the file and line (./Main.java:5: error: …). Exceptions happen while running; read the first line for the type and the at … lines for where.
error: cannot find symbol— a typo in a name, a variable used outside its block, or a missingimport.error: incompatible types: String cannot be converted to int— convert withInteger.parseInt(text).error: missing return statement— some path through the method does notreturn.error: class Geometry is public, should be declared in a file named Geometry.java— rename the file or the class.error: ';' expected— usually on the line above the one shown.NullPointerException— calling a method onnull; the message names the variable that was null.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3— indexes run from 0 tolength - 1.NumberFormatException: For input string: "x"— the text is not a number.NoSuchElementExceptionfromScanner— there is no more input; fill in the Input tab.
Main.java
public class Main {
public static void main(String[] args) {
String[] values = {"10", "x", "7"};
int total = 0;
for (String v : values) {
try {
total += Integer.parseInt(v);
} catch (NumberFormatException e) {
System.out.println("skipped " + v);
}
}
System.out.println("total: " + total);
}
}
Output
skipped x total: 17