search
HomeJavajavaTutorialWhat are the common running errors in Java?

What are the common running errors in Java?

Nov 18, 2019 pm 01:38 PM
javaabnormalRun error

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!

Statement
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
Why can't JavaScript directly obtain hardware information on the user's computer?Why can't JavaScript directly obtain hardware information on the user's computer?Apr 19, 2025 pm 08:15 PM

Discussion on the reasons why JavaScript cannot obtain user computer hardware information In daily programming, many developers will be curious about why JavaScript cannot be directly obtained...

Circular dependencies appear in the RuoYi framework. How to troubleshoot and solve the problem of dynamicDataSource Bean?Circular dependencies appear in the RuoYi framework. How to troubleshoot and solve the problem of dynamicDataSource Bean?Apr 19, 2025 pm 08:12 PM

RuoYi framework circular dependency problem troubleshooting and solving the problem of circular dependency when using RuoYi framework for development, we often encounter circular dependency problems, which often leads to the program...

When building a microservice architecture using Spring Cloud Alibaba, do you have to manage each module in a parent-child engineering structure?When building a microservice architecture using Spring Cloud Alibaba, do you have to manage each module in a parent-child engineering structure?Apr 19, 2025 pm 08:09 PM

About SpringCloudAlibaba microservices modular development using SpringCloud...

Treatment of x² in curve integral: Why can the standard answer be ignored (1/3) x³?Treatment of x² in curve integral: Why can the standard answer be ignored (1/3) x³?Apr 19, 2025 pm 08:06 PM

Questions about a curve integral This article will answer a curve integral question. The questioner had a question about the standard answer to a sample question...

What should I do if the Redis cache of OAuth2Authorization object fails in Spring Boot?What should I do if the Redis cache of OAuth2Authorization object fails in Spring Boot?Apr 19, 2025 pm 08:03 PM

In SpringBoot, use Redis to cache OAuth2Authorization object. In SpringBoot application, use SpringSecurityOAuth2AuthorizationServer...

Why can't the main class be found after copying and pasting the package in IDEA? Is there any solution?Why can't the main class be found after copying and pasting the package in IDEA? Is there any solution?Apr 19, 2025 pm 07:57 PM

Why can't the main class be found after copying and pasting the package in IDEA? Using IntelliJIDEA...

Java multi-interface call: How to ensure that interface A is executed before interface B is executed?Java multi-interface call: How to ensure that interface A is executed before interface B is executed?Apr 19, 2025 pm 07:54 PM

State synchronization between Java multi-interface calls: How to ensure that interface A is called after it is executed? In Java development, you often encounter multiple calls...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.