Home >Java >javaTutorial >Java exception collection
Keywords: Java oundsException
Security violation Principle exception: SecurityException File ended exception: EOFException File not found exception: FileNotFoundException String converted to number exception: NumberFormatException Operation database exception: SQLException Input and output exception: IOException Method not found exception :NoSuchMethodException 1. java.lang.nullpointerexception Everyone must encounter this exception often. The explanation of the exception is "the program encountered a null pointer". Simply put, it means that an uninitialized object is called or it does not exist. Object, 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. The occurrence of null pointers in array operations is in many cases a common mistake made by friends who are just beginning to learn programming, that is, they confuse 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 This exception is a common problem that occurs when many programmers who originally developed in development environments such as JB compile packages under JB under WTK. The explanation of the exception is "the specified class does not exist" , the main consideration here is whether the name and path of the class are correct. If the package is made under jb, package is usually added by default, so be careful to add the package path after switching to wtk. 3. 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 kind of exception, everyone should check it carefully. Check where mathematical operations are involved in your program to see if there is something wrong with the formula. 4. java.lang.arrayindexoutofboundsexception I believe many friends have often encountered this exception. The explanation of the exception is "array index out of bounds". Most of the programs now have array operations, so when calling the array You must check carefully to see if the subscript you are calling exceeds the range of the array. Generally speaking, explicit (that is, directly using a constant as the subscript) call is not prone to such errors, but implicit (that is, using a variable to represent the subscript) Standard) calls often make errors. Another situation is that 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 problem. abnormal. 5. 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. For example, if the volume parameter in the volume adjustment method This exception will occur if it is written as a negative number. Another example is the three values in the g.setcolor(int red, int green, int blue) method. If there are more than 255, this exception will also occur. Therefore, once this exception is discovered, we must What I did was to quickly check whether there was an error in the parameter passing in the method call. 6. java.lang.illegalaccessexception The explanation of this exception is "no access rights". This exception occurs when the application wants to call a class, but the current method does not have access rights to the class. Please pay attention to this exception when using packages in the program. There are many other exceptions, so I won’t list them one by one. What I want to explain is that a qualified programmer needs to have a considerable understanding of common problems in the program and corresponding solutions, otherwise he will just stop at writing. If you don't change the program, it will greatly affect your development. All descriptions of exceptions can be found in the API. java.lang.AbstractMethodError Abstract method error. Thrown when the application attempts to call an abstract method. java.lang.AssertionError Assertion error. Used to indicate an assertion failure. java.lang.ClassCircularityError Class circular dependency error. When initializing a class, this exception is thrown if a circular dependency between classes is detected. java.lang.ClassFormatError Class format error. Thrown when the Java virtual machine attempts to read a Java class from a file and detects that the contents of the file do not conform to a valid format for the class. java.lang.Error Error. Is the base class for all errors and is used to identify serious program operation problems. These problems usually describe some unusual situation that should not be caught by the application. Reason:1. The external resources accessed by the system are not closed, resulting in a large amount of waste of external resources, which may eventually cause the system to fail to operate normally;
2. The external resources accessed by the system are closed too many times, and the external system cannot handle them normally. ;
3. There is an abnormality in the external resources accessed by the system.
Solution:
1. Before accessing external resources, first check whether the resource (such as a database) can be connected or operated normally.
2. When accessing external resources, if a connection is made, the shutdown operation must be performed and only performed once.
3. Try to share external resources in the same operation to reduce the resource consumption of the operation and improve the execution efficiency of the program
java.lang.ExceptionInInitializerError
Initialization program error. Thrown when an exception occurs during the execution of a class's static initializer. Static initializer refers to the static statement segment directly included in the class.
java.lang.IllegalAccessError
Illegal access error. This exception is thrown when an application attempts to access or modify a field (Field) of a class or call its method, but violates the visibility declaration of the field or method.
java.lang.IncompatibleClassChangeError
Incompatible class change error. This exception is thrown when an incompatible change occurs in the class definition on which the method being executed depends. Generally, this error is easily caused when the declaration definition of some classes in the application is modified without recompiling the entire application and then running it directly.
java.lang.InstantiationError
Instantiation error. This exception is thrown when an application attempts to construct an abstract class or interface through Java's new operator.
java.lang.InternalError
Internal error. Used to indicate that an internal error has occurred in the Java virtual machine.
java.lang.LinkageError
Link error. This error and all its subclasses indicate that a class depends on other classes. After the class is compiled, the dependent class changes its class definition without recompiling all classes, thus causing the error condition.
java.lang.NoClassDefFoundError
Class definition not found error. This error is thrown when the Java virtual machine or class loader attempts to instantiate a class and cannot find the definition of the class.
java.lang.NoSuchFieldError
Field does not exist error. This error is thrown when an application attempts to access or modify a field of a class that does not have a definition for that field.
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.
java.lang.OutOfMemoryError
Out of memory error. This error is thrown when the available memory is insufficient for the Java virtual machine to allocate an object.
java.lang.StackOverflowError
Stack overflow error. This error is thrown when an application makes too many recursive calls and causes a stack overflow.
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.
java.lang.UnknownError
Unknown error. Used to indicate that an unknown serious error has occurred in the Java virtual machine.
java.lang.UnsatisfiedLinkError
Unsatisfied link error. Thrown when the Java virtual machine does not find a native language definition of a class that declares a native method.
java.lang.UnsupportedClassVersionError
Unsupported class version error. This error is thrown when the Java virtual machine tries to read a certain class file, but finds that the major and minor version numbers of the file are not supported by the current Java virtual machine.
java.lang.VerifyError
Verification error. This error is thrown when the validator detects an internal incompatibility or security issue in a class file.
java.lang.VirtualMachineError
Virtual machine error. Used to indicate a situation where a virtual machine has been destroyed or has insufficient resources to continue operations.
java.lang.ArithmeticException
Arithmetic condition exception. For example: integer division by zero, etc.
java.lang.ArrayIndexOutOfBoundsException
Array index out-of-bounds exception. Thrown when the index into the array is negative or greater than or equal to the array size.
java.lang.ArrayStoreException
Array storage exception. Thrown when an object of non-array declared type is stored in an array.
java.lang.ClassCastException
Class casting exception. Suppose there are classes A and B (A is not the parent class or subclass of B), and O is an instance of A, then this exception is thrown when O is forced to be constructed as an instance of class B. This exception is often called a cast exception.
java.lang.ClassNotFoundException
Class exception not found. This exception is thrown when the application attempts to construct a class based on a class name in string form, but cannot find the class file with the corresponding name after traversing the CLASSPAH.
java.lang.CloneNotSupportedException
Clone exception is not supported. When the Cloneable interface is not implemented or the clone method is not supported, calling its clone() method will throw this exception.
java.lang.EnumConstantNotPresentException
There is no exception for enumeration constants. This exception is thrown when an application attempts to access an enumeration object by name and enumeration type, but the enumeration object does not contain a constant.
java.lang.Exception
Root exception. Used to describe the situation the application wishes to capture.
java.lang.IllegalAccessException
Illegal access exception. This exception is thrown when the application attempts to create an instance of a class, access the class properties, or call the class methods through reflection, and the definition of the class, property, method, or constructor cannot be accessed at that time.
java.lang.IllegalMonitorStateException
Illegal monitoring state exception. This exception is thrown when a thread attempts to wait for the monitor of an object (O) that it does not own or notifies other threads to wait for the monitor of the object (O).
java.lang.IllegalStateException
Illegal state exception. This exception is thrown when a method is called in the Java environment and application before it is in a legal calling state.
java.lang.IllegalThreadStateException
Illegal thread state exception. When the county is not in the legal calling state of a certain method and the method is called, an exception is thrown.
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.
java.lang.InstantiationException
Instantiation exception. This exception is thrown when trying to create an instance of a class through the newInstance() method, and the class is an abstract class or interface.
java.lang.InterruptedException
Interrupted exception. This exception is thrown when a thread is waiting, sleeping or otherwise suspended for a long time, and other threads terminate the thread through Thread's interrupt method.
java.lang.NegativeArraySizeException
The array size is negative. This exception is thrown when an array is created with a negative size value.
java.lang.NoSuchFieldException
There is no exception in the property. This exception is thrown when accessing a non-existent property of a class.
java.lang.NoSuchMethodException
There is no exception in the method. This exception is thrown when accessing a non-existent method of a class.
java.lang.NullPointerException
Null pointer exception. This exception is thrown when the application attempts to use null where an object is required. For example: calling the instance method of the null object, accessing the properties of the null object, calculating the length of the null object, using the throw statement to throw null, etc.
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.
java.lang.RuntimeException
Runtime exception. Is the parent class for all exceptions that can be thrown during normal operation of the Java virtual machine.
java.lang.SecurityException
Security exception. An exception thrown by the security manager to indicate a security violation.
java.lang.StringIndexOutOfBoundsException
String index out-of-bounds exception. This exception is thrown when a character in a string is accessed using an index value that is less than 0 or greater than or equal to the sequence size.
java.lang.StringIndexOutOfBoundsException
String out-of-bounds errors and other string class related errors
Code segment 4:
String s_all_power = "1010011";
String s_access_power = s_all_power.substring(3,4);
Description:
The function of the above code snippet function is to obtain the 4th character in the string s_all_power.
Note:
Under normal circumstances, there will be no problem with the program. If for some reason, the length of s_all_power becomes shorter, the program will throw a string error.
Solution: When intercepting a string (substring, charAt), converting it to a byte array (getBytes), and converting a character array to a string (valueOf), first check the existence of the string object (whether it is empty or not) ) and length are checked before proceeding.
String s_all_power = "1010011";
if (s_all_power.length>4)
String s_access_power = s_all_power.substring(3,4);
java.lang.TypeNotPresentEx ception
The type does not exist abnormal. This exception is thrown when an application attempts to access a type as a string representation of the type name, but the type cannot be found based on the given name. The difference between this exception and ClassNotFoundException is that this exception is an unchecked (unchecked) exception, while ClassNotFoundException is a checked (checked) exception.
java.lang.UnsupportedOperationException
Unsupported method exception. Exception indicating that the requested method is not supported.
Exception
javax.servlet.jsp.JspException: Cannot retrieve mapping for action /Login (/Login is your action name)
Possible reasons
The action is not defined in struts-config.xml, or no matching action is found, for example, when used in a JSP file
------------------------ -------------------------------------------------- ----------------------------------------
Exception
org.apache.jasper .JasperException: Cannot retrieve definition for form bean null
Possible reason
This exception is because Struts did not find the form bean expected by the action based on the mapping in struts-config.xml. In most cases, it may be caused by the mismatch between the name attribute set in the form-bean and the name attribute set in the action. In other words, both action and form should each have a name attribute that matches exactly, including case. This error also occurs when there is no name attribute associated with the action. If the name attribute is not specified in the action, then there is no name attribute associated with the action. Of course, when action creates certain controls, such as jumping to the corresponding jsp page based on parameter values instead of processing form data, the name attribute is not used. This is also one of the ways to use action.
------------------------------------------------ -------------------------------------------------- ---------------
Exception
No action instance for path /xxxx could be created
Possible reasons
Special note: There are many situations that can cause this error to occur , so it is recommended that you increase the log/debug level of your web server so that you can see more information about potential errors that occur when trying to create the action class that you have already set in struts-config.xml The association is set in (that is, the < action> tag is added).
There are many reasons why the action class specified through the class attribute of the action tag in struts-config.xml cannot be found, for example: failed to locate the compiled . class file. Failure to place compiled .class file for the action in the classpath (In web development, the location of class is in WEB-INF/classes, so your action class must be in this directory. For example, your action class is located in WEB -INF/classes/action/Login.class, then when setting the attribute type of action in struts -config.xml, it is action.Login).
Spelling errors, this also happens from time to time, and is not easy to find, pay special attention to the first uppercase and lowercase letters and the name of the package.
------------------------------------------------ -------------------------------------------------- ---------------
Exception
javax.servlet.jsp.JspException: No getter method for property username of bean org.apache.struts.taglib.html.BEAN
Possible Reason
There is no getter method defined for a variable in the form bean
This error mainly occurs in the FormBean submitted by the form. When marked with struts, there must be a getUsername() method in the FormBean. Note the letter "U".
------------------------------------------------ -------------------------------------------------- ---------------
Exception
java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm
Possible reasons
This error mainly occurs when searching in the classpath The corresponding Java .class file cannot be found. If this error occurs when the web application is running, it is mainly because the specified class file is not in the web server's classpath (/WEB-INF/classes and /WEB-INF/lib). In the above error, the reason is that the ActionForm class cannot be found.
------------------------------------------------ -------------------------------------------------- ---------------
Exception
javax.servlet.jsp.JspException: Exception creating bean of class org.apache.struts.action.ActionForm: {1}
Possible reasons Not associating an ActionForm-descended class with an action can also lead to this error.
-------------------------------- -------------------------------------------------- ----------------------------------
Exception
javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
Possible reason
Either the tag identifying the Struts actionServlet or the tag mapping the .do extension or both are not declared in web.xml.
Typing or spelling errors in struts-config.xml can also cause this exception to occur. For example, a tag's closing symbol /> is missing. It's best to check it using struts console tool.
In addition, load-on-startup must be declared in web.
Another issue related to the use of load-on-startup is that using Struts to precompile JSP files may also cause this exception.
------------------------------------------------ -------------------------------------------------- ---------------
Exception
java.lang.NullPointerException at org.apache.struts.util.RequestUtils.forwardURL(RequestUtils.java:1223)
Possible reasons
The forward element in struts-config.xml is missing the path attribute. For example, it should be in the following form:
--------------------------------------------- -------------------------------------------------- --------------------------
Exception
javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html. BEAN in any scope
Probable Causes
Attempting to use form child elements outside the Struts form tag. This often happens when you use Struts html markup behind the scenes. Also note that you may use bodyless tags inadvertently. For example, the web server will treat it as a bodyless tag when parsing it. All tags used subsequently are considered to be outside this tag. If you use it again, it will be treated as a bodyless tag. One problem is that when using taglib to introduce the HTML tag library, the prefix value you use is not html.
------------------------------------------------ -------------------------------------------------- ---------------
Exception
javax.servlet.jsp.JspException: Missing message for key xx.xx.xx
Probable Causes
The value pair of this key is not in The resource file is defined in ApplicationResources.properties. If you often encounter this situation when using eclipse, eclipse will automatically delete the resource files in the classes directory when the project is recompiled.
If the resource file ApplicationResources.properties is not in the classpath, the resource file should be placed in the WEB-INF/classes directory, and of course it must be defined in struts-config.xml)
------------- -------------------------------------------------- --------------------------------------------------
Exception
Cannot find message resources under key org.apache.struts.action.MESSAGE
Possible reasons
Obviously, this error occurs when using resource files, and Struts does not find the resource files.
Implicitly trying to use message resources that are not available (such as using empty html:options tag instead of specifyingthe options in its body -- this assumes options are specified in ApplicationResources.properties file)
XML parser issues -- too many , too few, incorrect/incompatible versions
--------------------------------------------- -------------------------------------------------- -----------------------
Strange and seemingly random characters in HTML and on screen, but not in original JSP or servlet.
Possibly Reason
It is incorrect to mix the Struts html:form tag with standard HTML tags.
The encoding style used is not supported on this page.
------------------------------------------------ -------------------------------------------------- ---------------
Exception
"Document contained no data" in Netscape
No data rendered (completely empty) page in Microsoft Internet Explorer
Possible reasons
Use a Derived classes from Action do not implement the perform() method or execute() method. What is implemented in Struts1.0 is the perform() method, and what is implemented in Struts1.1 is the execute() method, but Struts1.1 is backward compatible with the perform() method. But if you use Struts1.1 to create a derived class of Action and implement the execute() method, and you run it in Struts1.0, you will get "Document contained nodata" error message in Netscape or a completely empty (no HTML whatsoever) page rendered in Microsoft Internet Explorer.” error message.
-------------------------------- -------------------------------------------------- ---------------------------------------
Exception
ServletException: BeanUtils.populate
Solution
When using Struts to upload files, I encountered javax.servlet.ServletException: BeanUtils.populate exception.
My ActionServlet did not use the BeanUtils tool classes. Later, I carefully checked the code and found that it was in the jsp file. I forgot to add enctype= "multipart/form-data". So when you encounter an error or exception when writing a program, you should consider the possibility of the problem from many aspects, and think of things other than system prompts
------ -------------------------------------------------- -------------------------------------------------- ------------------
1. After defining Action, if name is specified, a FormBean with the same name must be defined to perform form mapping. 2. If after defining Action, "No input attribute for mapping path..." error occurs when submitting the page , you need to define the redirected page in its input attribute. 3. If the "Batch update row count wrong:..." error occurs when inserting new data, it means that the type of key specified in XXX.hbm.xml is original Type (int, long), because this type will automatically assign a value, and this value will often make the system think that the record already exists. The correct method is to use java.lang.Integer or java.lang.Long objects. 4. If "argument type mismatch" error occurs when inserting data. It may be that you use special objects such as Date. Because struts cannot automatically convert from String type to Date type, you need to manually convert String type to Date type in Action.5 . In Hibernate, Query's iterator() method is much faster than the list() method. 6. If an "equal symbol expected" error occurs, it means that your strtus tag contains another tag or variable, for example:
or
"/>
Such a situation...
---------------------------------- -------------------------------------------------- ----------------------------------------
Error: Exception in thread "main" org. hibernate.exception.SQLGrammarException: Could not execute JDBC batch update Cause and solution: Because the *.hbn.xml tool generated by Hibernate Tools (or Eclipse's own Database Explorer) contains catalog="***" (* represents the database name) For such an attribute, just delete the attribute
--------------------------------------------- -------------------------------------------------- ------------------------------------
Error: org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)
Cause and solution:
Method 1 Delete the cascade on the Set side
Method 2 Delete it after resolving the association
Method 3 Add on the many-to-one side cascade but the value cannot be none
The last trick:
Check whether hashCode equals uses id as the only marked option; there is no problem when I use uuid.hex; but it doesn’t work when I use native. Why? manage? Delete it!
------------------------------------------------ -------------------------------------------------- --------------------------
Question: I used Tomcat 5.5.12 today and found that the system that used to be very useful can no longer be used. , repeated testing found that taglib cannot be included in the page, otherwise the following prompt will appear: HTTP Status 500 -type Exception reportMessage description The server encountered an internal error () that prevented it from fulfilling this request.exceptionorg.apache.jasper.JasperException: /index .jsp(1,1) Unable to read TLD "META-INF/tlds/struts-bean.tld" from JAR file "file:*****/WEB-INF/lib/struts.jar": Reason: Update The jar in the lib folder used in the project is included, and servlet.jar and jsp-api.jar are also released when publishing. Solution: Delete jsp-api.jar to solve this problem. ----------------------- ---------------------------- -------------------------------------------------- ------------------------
Error: java.lang.NullPointerException
Cause: It was found that there is no dao instance, manage instance, etc. that need to be injected. Injection (commonly known as null pointer exception) solution: At this time, you should check the log file; the default is the log file of the application server, for example, Tomcat is [Tomcat installation directory]/logs; you will find a prompt: It may be: org.springframework .beans.factory.BeanCreationException: Error creating bean with name 'sf' defined in ServletContextresource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception isorg.hibernate.HibernateException: could not configure from URL: file: src/hibernate.cfg.xmlorg.hibernate.HibernateException: could not configure from URL: file:src/hibernate.cfg.xml…………………….Caused by: java.io.FileNotFoundException: srchibernate.cfg. The xml may be: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined inServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception isorg.hibernate.MappingException: Resource : com/mcc/coupon/model/UserRole.hbm.xml not foundorg.hibernate.MappingException: Resource: com/mcc/coupon/model/UserRole.hbm.xml not found Then you will know that the reason is because the configuration file is parsed out There is an error, which cannot be seen through the Web page. What's more, it's an error in the persistence mapping file, which results in it not being parsed; of course, the function you need cannot be used.
------------------------------------------------ -------------------------------------------------- --------------------------
Error: StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
javax.servlet.jsp.JspException: Cannot retrieve mapping for action /settlementTypeManage
Or: type Status report message Servlet action is not available description The requested resource (Servlet action is not available) is not available.
Cause: Same as above
------------------------------------------------ -------------------------------------------------- ------------------------
Error StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang.ClassNotFoundException: org. apache.struts.taglib.bean.CookieTei interface error detailed description:
org.apache.jasper.JasperException: Failed to load or instantiate TagExtraInfo class: org.apache.struts.taglib.bean.CookieTei
Cause and solution: < ;Option 1> Your tags starting with "html:" are not placed in a
---------- -------------------------------------------------- -------------------------------------------------- --------------
java.lang.IllegalStateException: getOutputStream() has already been called for this responses
Cause: There is out.write(" in the servlet code generated by the web container "), this conflicts with response.getOutputStream() called in JSP 1. That is, the Servlet specification states that you cannot call both response.getOutputStream() and response.getWriter(). No matter which one is called first, the call will IllegalStateException should be thrown at the second time, because in jsp, the out variable is actually obtained through response.getWriter. Your program uses both response.getOutputStream and out variable, so the above error occurs.
2. Since the jsp container will call the releasePageContet method to release the used PageContext object after processing the request, and also call the getWriter method. Since the getWriter method conflicts with the getOutputStream method related to using streams in the jsp page, this exception will occur.
Solution:
//Output the image to the page
ImageIO.write(image, "JPEG", response.getOutputStream());
Add 2 sentences;
out.clear();
//The meaning is: clear the cached content
out = pageContext.pushBody();
//Return a new BodyContent (representing the BODY part of an HTML page)
//Save the object of the JspWriter instance out
//Update the content of the out attribute of PageContext
--------------------------------------------- -------------------------------------------------- ----------------------------------
bad number
Cause: Project version and JDK version Incompatible
Solution: windows-preferences-server-Integrated Sandbox-Myeclise tomcat 6-Select the JDK consistent with the project version
-------------------------- -------------------------------------------------- -------------------------------------------------- --
Connection reset by peer: socket write error problem
This problem is usually caused by the client canceling the connection before the connection is fully established. For example, the user presses the "Stop" button on the browser. Generally, Said there was no problem. But if it appears frequently, it means that the response time of many clients connecting to the Apache server is too long. It may be a network problem or a server performance problem. There may be some problems with your network connection. When your data is transmitted, it may be due to The waiting time is too long, but the connection check time limit set in the server segment is certain, then this situation may occur!
but the more common reasons are:
1: The number of concurrent connections of the server exceeds its carrying capacity. The server will down some of the connections;
2: The client closed the browser, but the server is still sending data to the client;
3: The browser pressed Stop;
4: The server responded to the client As a result, it was blocked by the firewall.