Several cases of java.lang.nullpointerexception error reporting:
1. String variable is not initialized
2. Interface type objects are not initialized with specific classes, such as:
List stuList ; In this case, a null pointer exception will be reported
List stuList = new ArrayList(); After initialization, no error will be reported
3. When the value of an object is null and you do not judge it as null, a null pointer exception will also be reported
Therefore, add a judgment before the code, such as:
if(ObjId != null);
For string type objects, you can make the following judgment:
if(objectStr !== null && amp; !“”. equals(objectStr))
Of course, you can also judge whether it is not an empty string:
if(objectStr !== null && amp; !“”. equals(objectStr.trim()))
Example: when I edit a page, it will pop up a custom error.jsp page code block (reporting system error)
Check the log: (an error is reported on line 54 — the picture is badly cut)
Because doc.getid does not make judgment, null pointer exception is reported when ID does not exist… (for case 3)
Similar Posts:
- Python: `if not x:` VS `if x is not None:` VS `if not x is None:`
- How to Solve Console error: index: 0, size: 0
- How to Solve Request processing failed; nested exception is java.lang.NullPointerException
- :exception: java.lang.reflect.InvocationTargetException: null
- [Solved] Cannot call sendRedirect() after the response has been committed
- [Solved] Exception in thread “main” java.util.ConcurrentModificationException
- An error is reported when traversing the list collection to delete elements
- [Solved] Mybatis Mapping Error: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘id’ in ‘class java.lang.String
- JAVA set to determine the null: List.isEmpty() & null == List && List.size()==0
- [Solved] java.lang.IllegalStateException: Fragment already added: xxxxFragment