This time I will write about the error that appears in java.
Here are some compilation errors that are more common to beginners and how to deal with them.
And so on.
The Java description rule is to add a semicolon ";" to each instruction.
semicolon";Is insufficient
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!") //← Semicolon ("";”) Is not enough
}
}
If you don't have enough double quotes "" "at the end of the string, you'll get this error:
Insufficient double quotation mark "" "
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!); ← World!After the""There is no
}
}
This is caused by putting "full-width blank" characters in the place where "half-width blank" characters should be put.
Half-width white space
public □ class HelloWorld { //← Double-byte space after public (□)
public static void main(String[] args) {
System.out.println("Hello World!")
}
}
To give an example Whereas the class name described in the source file is "Hello World" It occurs because the file name is "Hello.java".
In Java, write one class in one file The file name is "class name.java".
Dozens of lines of programs lack parentheses for paragraphs like if () {} and for () {} It's very difficult to understand.
Closing bracket "}」
public static void main(String[] args) {
System.out.println("Hello World!")
// ← 「}There is no
}
It gets a little difficult, and I will introduce the error contents that appear in arrays and if syntax.
Click here for the main contents
java.lang.NullPointerException This error occurs when trying to access a null object. This error is relatively common during programming and is called "nullpo" by engineers.
java.lang.ArrayIndexOutOfBoundsException An error that occurs when you specify an element that does not exist as an array index I also introduced the error example earlier. Where there are only 1-9 indexes as array indexes Occurs when trying to set a value for an index of 10.
Countermeasures
java.lang.NumberFormatException This error tried to convert (cast) a string value to a number Occurs when an incorrect numerical value is set in the character string.
java.lang.ClassCastException This error occurs when trying to cast a class to a class that cannot be converted.
java.lang.ArithmeticException This error occurs when an illegal arithmetic process is performed in the calculation of a numerical value. For example, this error occurs when a mathematically impossible "division by zero (10 ÷ 0, etc.)" occurs.
java.lang.NoClassDefFoundError When calling a method or trying to create an instance This is an error that Java cannot read the class definition.
java.lang.OutOfMemoryError Java uses two memory areas at runtime, the stack area and the heap area. This error occurs when the memory size of the heap area required to execute the program is insufficient.
A heap area is a memory area to which an instance of an object is allocated, such as class and method definitions.
Recommended Posts