Java.lang.NullPointerException
This exception is often encountered, the exception is interpreted as "the program encountered a null pointer", simply called an uninitialized object or a nonexistent object, this error often occurs in the
Create a picture, call an array in these operations, the slice is not initialized, or the picture is created with a path error, and so on. A null pointer appears in an array operation, and in many cases, some of the friends who are just beginning to learn programming
A common mistake is to confuse the initialization of arrays with the initialization of an array of 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,
is still empty, so it is necessary to initialize each element (if it is to be called).
Often occurs in JSP programming: if (Request.getparameter ("username"). Equals ("xxx")), Out.println (Session.getattribute ("Record")), and so on. Solve this
The problem is to use a null comparison before using the method:
if (Request.getparameter ("username")!=null)
{if if (Request.getparameter ("username").
Equals ("xxx")) ...}
No.2 Java.lang.ClassNotFoundException
This anomaly is a lot of developers originally developed in the development environment such as JB, put JB under the package under the WTK to compile frequently problems, the explanation of the exception is "The specified class does not exist", here the main test
Consider the name and path of the class is correct, if it is in the JB under the package, 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 divided by 0 such an operation will be such an exception, for this anomaly, we have to check the program involved in the number
Where the math is going, the formula is wrong.
No.4 Java.lang.ArrayIndexOutOfBoundsException
This exception is believed many friends also often encountered, the exception 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, see
The subscript that you call is not 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 variable is the subscript) call is often wrong
, there is also the case that the length of the array defined in the program is determined by certain methods, not in advance, and it is better to look at the length of the array before this exception occurs.
。
No.5 java.lang.IllegalArgumentException
The explanation for this exception is "parameter error of the method", and many of the methods in the J2ME class library will cause such errors in some cases, such as the volume parameter in the volume adjustment method if written as a negative number will
This exception occurs, such as g.setcolor (int red,int green,int blue) Three values in this method, if there are more than 255 of this exception will also occur, so once found that the XOR
Often, all we have to do is hurry and check that the parameter passing in the method call is not an error. 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. The application of the package
Attention to this anomaly.
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. It is common to modify the declaration definitions of some classes in the application without having to weigh the entire application
This error is easily thrown when the new compilation is run directly.
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 has been compiled, the dependent class has changed its class definition without recompiling all the classes, which in turn raises an 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.
There are many other exceptions, here I do not enumerate, but to illustrate, a qualified programmer, the program needs to have a good understanding of common problems and corresponding solutions, otherwise just stay in writing procedures and will not change the program, will greatly affect their own development. The recognition of anomalies is one of the most important in the standards that really coding your level of performance. The full description of the exception is available in the API. We also do not have to put all of the content in the brain, as long as the common anomalies have some impression, in the real encounter to know where to find the almost, after all, the most painful Java programmer is its knowledge capacity is too large, and we encounter new errors and new problems and new knowledge every day, So it is most important to grasp a skill that belongs to your own line-up anomaly.
Top 10 common exceptions in Java