Summary of Common Java exceptions

Source: Internet
Author: User
Tags class definition

1, java.lang.NullPointerException (null pointer exception)
An uninitialized object or an object that does not exist is called

Often appear in the Create picture, call array in these operations, than the slice is not initialized, or the picture is created when the path error and so on. A null pointer appears in the array operation,
The initialization of the array and the initialization of the set element are confused. The initialization of an array is the space required for the allocation of arrays, and the initialized array, where the elements are not instantiated,
is still empty, so it is necessary to initialize each element (if it is to be called).

2, Java.lang.ClassNotFoundException

The specified class does not exist

The main consideration here is whether the name and path of the class are correct, usually when a program attempts to load a class by using a string that may throw an exception

For example: Call Class.forName ();

    或者调用ClassLoad的finaSystemClass();或者LoadClass();

3, Java.lang.NumberFormatException

string conversion to numeric exception

This exception is thrown when an attempt is made to convert a string to the specified number type, and the string does not satisfy the format required by the number type. This is allowed when the data "123456" of the character type is now converted to numeric data.

However, if the character data contains non-numeric characters, such as 123#56, an exception occurs when converted to a numeric type. The system catches the exception and processes it.

4, Java.lang.IndexOutOfBoundsException

Array subscript out of bounds exception

Looking at the array of calls or the subscript value of a string is not beyond the range of the array, generally speaking, the display (that is, directly with the constant subscript) call is not easy to make such a mistake, but the implicit (that is, the use of variable-subscript) calls are often wrong, there is a situation, The length of the array defined in the program is determined by certain methods and is not declared beforehand, so it is better to look at the length of the array before this exception occurs.

5, Java.lang.IllegalArgumentException

Parameter error for method

For example, g.setcolor (int red,int green,int Blue) This method of three values, if there are more than 255 of the exception will also occur, so once you find this exception, we have to do is to quickly check the method call in the parameter passed is not an error occurred.

6, Java.lang.IllegalAccessException

No access rights

This exception occurs when the application is calling a class, but the current method does not have access to the class. Note This exception in cases where the package is used in the program

7, Java.lang.ArithmeticException

Mathematical Operation Anomaly

Such an exception occurs when an arithmetic operation is divided by 0.

8, Java.lang.ClassCastException

Data type Conversion exception

This exception is thrown when an attempt is made to force a downward transformation on an object, but the object is not convertible and cannot be converted to an instance of its child class, such as the following code.

                         Object obj = new Integer(0);                         String str = obj;

9, Java.lang.FileNotFoundException

File not found exception

This exception is thrown when a program tries to open a nonexistent file for read-write. The exception is thrown by the constructor declaration of the Fileinputstream,fileoutputstream,randomaccessfile

Even if the file being manipulated exists but is inaccessible for some reason, such as opening a read-only file for writing, these construction methods still throw an exception

10, Java.lang.ArrayStoreException

Array Store exception

An exception is thrown when an attempt is made to save an object of type incompatible type to an object[] array

                      Object[] obj = new String[3];                      obj[0] = new Integer(0);

11, Java.lang.NoSuchMethodException

method does not exist exception

An exception is thrown when a program attempts to create an object through reflection, access (modify or Read) a method, but the method does not exist

12, Java.lang.NoSuchFiledException

method does not exist exception

An exception is thrown when a program attempts to create an object through reflection, access (modify or read) a filed, but the filed does not exist

13, Java.lang.EOFException

File has ended exception

An exception is thrown when the program encounters the end of a file or stream during the input process. Therefore, the exception is used to check whether the end of the file or stream is reached

14, Java.lang.InstantiationException

Instantiating an exception

When you try to create an instance of a class through the class's Newinstance () method, but the program cannot create the object through the constructor, it throws

Class object represents an abstract class, interface, array class, base type
The class represented by this class does not have a corresponding constructor

15, Java.lang.InterruptedException

Aborted exception

This exception is thrown when a thread is in a long wait, hibernate, or other paused state while another thread terminates the thread through the interrupt method of the thread.

16, Java.lang.CloneNotSupportedException
Cloning exceptions are not supported

When the Cloneable interface is not implemented or the Clone method is not supported, the exception is thrown by calling its clone () method.

17, Java.lang.OutOfMemoryException
Low Memory error

This error is thrown when the available memory is insufficient for a Java virtual machine to be assigned to an object.

18, Java.lang.NoClassDefFoundException
Class definition error not Found

This error is thrown when a Java virtual machine or class loader attempts to instantiate a class and cannot find the definition of the class.

Violation of security principle exception: Secturityexception

Manipulating Database Exceptions: SQLException

Input/Output exception: IOException

Communication exception: SocketException

Summary of Common Java exceptions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.