In Java, you can write several methods to restore some of the following exceptions. Then in the corresponding processing, this can be in the subsequent coding to encounter similar problems, can be quickly resolved. Improve your coding efficiency.
Java.alng.NullPointerException
This exception everyone must often encounter, the exception of the explanation is "The program encountered a null pointer ", simply called an uninitialized object or a non-existent object, this error often occurs in the creation of images, call array of these operations, the chip is not initialized, or a path error when creating a picture, and so on. A null pointer appears in an array operation, and in many cases is a common mistake made by friends who are just beginning to learn programming, which confuses the initialization of arrays and the initialization of the array elements. The initialization of an array is the space required for the allocation of arrays, and the initialized array, where the elements are not instantiated, are still empty, so you also need to initialize each element (if it is to be called).
The solution to this problem is to make a comparison of the empty sentences before use:
if (Request.getparameter ("username")!=null)
{if if (Request.getparameter ("username").
Equals ("xxx")) ...}
No.2 Java.lang.ClassNotFoundException
This anomaly is a lot of programmers developed in the development environment, such as JB, put the package under the JB under WTK to compile the frequently occurring problem, the explanation of the exception is "The specified class does not exist ", Here is the main consideration of the class name and path is correct, if the package is done under the JB, is usually the default plus packages , so go to the WTK to pay attention to the package path Add.
No.3 java.lang.ArithmeticException
The explanation of this anomaly is "mathematical operation Anomaly ", for example, the program appears (1/0) divided by 0 such an operation will be such an exception, for this anomaly, we have to check the procedure of their own procedures involved in the mathematical operation of the place, the formula is not inappropriate.
No.4 Java.lang.ArrayIndexOutOfBoundsException
This exception is believed many friends also often encountered, abnormal explanation is "array subscript out of Bounds", now most of the program has an array of operations, so in the call arrays must be carefully checked, to see whether the subscript is beyond the range of the array, in general, 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 also a case, the length of the array defined in the program is determined by certain methods, is not declared beforehand, it is better to look at the array of Length to avoid this exception
No.5 java.lang.IllegalArgumentException
The explanation of this exception is "parameter error of the method ", and many methods in the J2ME class library will cause such errors in some cases, such as the volume parameter in the volume adjustment method if it is written as a negative number, then the exception will occur, such as g.setcolor (int Red,int Green,int Blue) This method has three values, and if there are more than 255, this exception will also occur, so once you find this exception, all we have to do is hurry to check if the parameter passing in the method call is wrong.
No.6 Java.lang.IllegalAccessException
This exception is interpreted as "No Access ", which occurs when the application is calling a class, but the current method does not have access to the class. Be aware of this exception in cases where the package is used in the program .
No.7 Java.lang.IncompatibleClassChangeError
Incompatible class change error. This exception is thrown when an incompatible change is made to the class definition on which the method being executed depends. This error is easily thrown when you modify the declaration definition for some classes in your app without recompiling the entire application.
No.8 Java.lang.InstantiationError
Instantiation of the error. This exception is thrown when an application attempts to construct an abstract class or interface through Java's new operator.
No.9 Java.lang.LinkageError
Link error. The error and all its subclasses indicate that a class depends on another class, and after that class is compiled, the dependent class changes its class definition without recompiling all of the classes, which in turn raises the error condition.
No.10 Java.lang.StackOverflowError
Stack overflow error. This error is thrown when the hierarchy of an application recursive call is too deep to cause a stack overflow.
No.11 classcastexception: Type cast exception
A class is a numeric class, and, due to misoperation, incorrectly rewrites a numeric class to a numeric class to convert a numeric class into a string class, resulting in an exception. For example, a data he is "ss", String type , but you use Integer.parseinteger () to convert to int type , which is of course wrong
No.12 negativearrayexception: Array negative subscript exception
No.13 secturityexception: Breach of security principle exception
No.14 eofexception: File has ended exception
No.15 filenotfoundexception: File not found exception
No.16 NumberFormatException: String conversion to numeric exception
No.17 SQLException: Manipulating Database exceptions
No.18 IOException: Input and output exception
No.19 Nosuchmethodexception: Method Not found exception
No.20 Java.lang.AbstractMethodError: Abstract method error. Thrown when an application attempts to invoke an abstract method
No.21 Java.lang.AssertionError: Assertion is wrong. Used to indicate a condition in which an assertion failed
No.22 Java.lang.ClassCircularityError
Class loop-dependent error. When a class is initialized, the exception is thrown if a circular dependency between the classes is detected.
No.23 Java.lang.ClassFormatError
The class format is incorrect. thrown when a Java virtual machine attempts to read a Java class from a file and detects that the contents of the file do not conform to the valid format of the class.
No.24 Java.lang.Error
Error. is the base class for all errors that identify serious program run issues. These problems often describe anomalies that should not be captured by the application.
No.25 Java.lang.ExceptionInInitializerError
Initialization program error. Thrown when an exception occurs during the execution of a static initializer for a class. Static initializers refer to static statement segments that are included directly in the class .
No.26 Java.lang.IllegalAccessError
Illegal access error. This exception is thrown when an application attempts to access, modify, or invoke the domain (field) of a classor call its methods, but violate the visibility declaration of a domain or method.
No.27 Java.lang.InternalError
Internal error. Used to indicate an internal error occurred with the Java virtual machine.
No.28 Java.lang.NoClassDefFoundError
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.
No.29 Java.lang.NoSuchFieldError
There are no errors in the domain. This error is thrown when an application attempts to access or modify a domain of a class that does not have a definition of that domain in the definition of that class.
No.30 Java.lang.NoSuchMethodError
Method has no errors. This error is thrown when an application attempts to invoke a method of a class that does not have the definition of the method in the definition of the class.
No.31 Java.lang.OutOfMemoryError
Insufficient memory error. This error is thrown when the available memory is insufficient for a Java virtual machine to be assigned to an object.
No.32 Java.lang.ThreadDeath
The thread ends. This error is thrown when the stop method of the thread class is called to indicate the end of the thread.
no.33 Java.lang.UnknownError
Unknown error. Used to indicate a situation in which a Java virtual machine has an unknown critical error.
No.34 Java.lang.UnsatisfiedLinkError
An unsatisfied link error. thrown when a Java virtual machine does not find a class that is declared as a native language definition of the native method.
No.35 Java.lang.UnsupportedClassVersionError
Unsupported class version error. This error is thrown when the Java Virtual machine attempts to read a class file, but discovers that the primary and minor version number of the file is not supported by the current Java virtual machine.
No.36 Java.lang.VerifyError
Validation error. This error is thrown when the validator detects an internal incompatibility or security issue in a class file.
No.37 Java.lang.VirtualMachineError
Virtual machine error. A condition that indicates that the virtual machine is compromised or that the resource required to continue performing the operation is insufficient
Java Basics-Common exceptions and errors