Common exceptions in Java Development
1. java. lang. NullPointerException
This exception is common. The exception is interpreted as "the program encounters a null pointer". Simply put, it calls an uninitialized object or a non-existent object, this error often occurs when you create an image. When you call an array, the image is not initialized, or the path when the image is created is incorrect. There is a null pointer in array operations. In many cases, it is a common mistake for friends who are just learning programming, that is, to confuse array initialization with array element initialization. Array initialization allocates the required space to the array. The elements in the initialized array are not instantiated and are still empty, therefore, you also need to initialize each element (if you want to call it)
2. java. lang. ClassNotFoundException
This exception is a problem that occurs frequently when many programmers originally developed in development environments such as JB compile the packages under JB in WTk. The exception is interpreted as "the specified class does not exist ", here, we mainly consider whether the class name and path are correct. If the Package is made under JB, the Package is usually added by default, therefore, add the Package path after you go to WTK.
3. java. lang. ArithmeticException
This exception is interpreted as "mathematical operation exception". For example, if an operation such as dividing by zero occurs in a program, this exception occurs, we need to check whether the formula is inappropriate in the mathematical operations involved in our program.
4. java. lang. ArrayIndexOutOfBoundsException
This exception is often encountered by many friends. The exception is explained as "array subscript out of bounds". Most of the programs now have Array Operations, therefore, when calling an array, you must carefully check whether the subscript you call exceeds the range of the array. In general, it is displayed (that is, the constant is used as the subscript directly) this is not easy to make calls, but implicit (that is, using variables to represent subscript) calls often encounter errors, the length of the array defined in the program is determined by some specific methods, not stated in advance. At this time, it is best to first check the length of the array to avoid this exception.
5. java. lang. IllegalArgumentException
This exception is interpreted as "parameter errors of methods". Many methods in the j2s' class libraries may cause such errors in some situations, for example, if the volume parameter in the volume adjustment method is written as a negative number, this exception occurs, for example, g. setColor (int red, int green, int blue) three values in this method, if there is more than 255, this exception will also occur, so once this exception is found, what we need to do, check whether the parameter passing in the method call is incorrect.
6. java. lang. IllegalAccessException