Java.lang.NullPointerException Several cases of error:
1. String variables not initialized;
2. Objects of the interface type are not initialized with a specific class, such as:
List stulist; In this case, the null pointer exception is reported;
List stulist = new ArrayList (); After initialization, no error is made.
3. When the value of an object is empty, and you do not determine the empty case, the null pointer exception is also reported;
So put a judgment in front of the code, like this:
if (ObjId! = null);
A string type object can be judged as follows:
if (Objectstr!) ==null &&! "". Equals (OBJECTSTR))
Of course, you can also make a more judgment, whether it is not an empty string:
if (Objectstr!) ==null &&! ". Equals (Objectstr.trim ()))
Example: When I edit a page, it pops up a custom error.jsp page code block (report system error)
Check the log: (the 54th line error--the picture has been badly cut)
Since Doc.getid did not make a judgment, when the ID does not exist The Times null pointer exception ... (For Case 3)
Several cases of java.lang.NullPointerException error