Home > Java > javaTutorial > body text

What are the common running errors in Java?

青灯夜游
Release: 2019-11-18 13:38:09
Original
4755 people have browsed it

What are the common running errors in Java?

In Java, runtime errors are divided into two categories according to their nature: errors and exceptions.

All exceptions in Java are objects generated by subclasses of the Throwable class. All exception classes are subclasses of the Throwable class or subclasses of subclasses. The Throwable class is a direct subclass of the Object class, and the Error class and Exception class are two direct subclasses of the Throwable class.

What are the common running errors in java?

1. java.lang.NullPointerException

The explanation of this exception is "the program encountered a null pointer". Simply put, it means that an uninitialized object or an uninitialized object was called. Existing objects, this error often occurs in operations such as creating images and calling arrays. For example, the image is not initialized, or the path when creating the image is wrong, etc.

A null pointer appears during an array operation, which confuses the initialization of the array with the initialization of the array elements. The initialization of the array is to allocate the required space to the array, and the elements in the initialized array have not been instantiated and are still empty, so each element needs to be initialized (if it is to be called).

2. java.lang.ClassNotFoundException

The explanation of the exception is "the specified class does not exist". Here we mainly consider whether the name and path of the class are correct

3. java.lang.ArrayIndexOutOfBoundsException

The explanation of this exception is "array subscript out of bounds". Most of the programs now have operations on arrays, so when calling an array, you must check carefully to see what is being called. Does the subscript exceed the range of the array?

Generally speaking, explicit (that is, using a constant as a subscript directly) calls are less likely to make such errors, but implicit (that is, using variables to represent subscripts) calls often cause errors. There is another situation, The length of the array defined in the program is determined by some specific methods and is not declared in advance. At this time, it is best to check the length of the array first to avoid this exception.

4. java.lang.NoSuchMethodError

There is no error in the method. This error is thrown when the application attempts to call a method of a class that does not have a definition for the method.

5.java.lang.IndexOutOfBoundsException

Index out-of-bounds exception. This exception is thrown when the index value of a sequence is less than 0 or greater than or equal to the sequence size.

6, java.lang.NumberFormatException

Number format exception. This exception is thrown when an attempt is made to convert a String to a specified numeric type and the string does not meet the format required by the numeric type.

7.java.sql.SQLException

Sql statement execution exception

8.java.io.IOException

Input and output exception

9.java.lang.IllegalArgumentException

The explanation of this exception is "method parameter error". Many methods in j2me class libraries will cause such errors in some cases, such as the volume adjustment method. This exception will occur if the volume parameter is written as a negative number. Another example is the three values ​​​​in the g.setcolor(int red, int green, int blue) method. This exception will also occur if there are more than 255, so once this exception is found , what we have to do is to quickly check whether there is an error in the parameter passing in the method call.

10, java.lang.IllegalAccessException

The explanation of this exception is "no access permission". When the application wants to call a class, but the current method does not have access permission to the class This exception will occur. Please pay attention to this exception when using packages in the program.

11.java.lang.arithmeticexception

The explanation of this exception is "mathematical operation exception". For example, if an operation such as division by zero occurs in the program, such an exception will occur. For this If there is an abnormality, everyone should carefully check the mathematical operations involved in their program to see if there is something wrong with the formula.

The above is the detailed content of What are the common running errors in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!