The null pointer exception problem is mostly an error in integer automatic unpacking
Error code:
Integer a=null;
if(a==1||a==null){
System.out.println("111");
}
error reporting: java.lang.nullpointerexception font>
Error reporting reason:
Integer object is null. In the process of automatic unpacking, obj.xxxvalue will throw NullPointerException
Problem solving:
If you want to continue the multi conditional judgment, you should put the judgment empty in the first place
Modification code:
Integer a=null;
if(a==null||a==1){
System.out.println("111");
}
To avoid another null pointer like exception error, you need to master the knowledge of null in Java. You can refer to another article What you should know about null in Java
Read More:
- Maven package error reporting java.lang.stackoverflowerror solution
- Android studio — java.lang.nullpointerexception(no error message)
- About the error querying database. Cause: java.lang.nullpointerexception reported in mybatis
- Method threw ‘java.lang.NullPointerException‘ exception. Cannot evaluate com.sun.proxy.xxx
- Idea community version starts Tomcat to report error running ‘XXXXXX’: java.lang.NullPointerException
- Pychar console error: xmlrpc.client.Fault : Fault 0: ‘ java.lang.NullPointerException
- Eclipse:An error has occurred. See error log for more details. java.lang.NullPointerException
- The @ Autowired annotation in springboot is invalid in ordinary classes. How to solve and use the null pointer exception java.lang.nullpointerexception
- A problem occurred configuring project ‘:x x x‘. > java.lang.NullPointerException (no error message)
- Java:java.lang.OutOfMemoryError : GC overhead limit exceeded solution
- Error in idea compilation: java.lang.OutOfMemoryError Java heap space and java.lang.StackOverflowError
- java.lang.NoSuchMethodError: org.json.JSONObject.put(Java/lang/String; Java/util/Collection;) “209151;”
- Solution of Java resources error reporting
- Errorjava.lang.NullPointerException(no error message)
- Solution to error reporting in Java @ override
- java.lang.IllegalStateException Exception: cause analysis and solution
- appear java.lang.NoClassDefFoundError A kind of reason and solution of the mistake
- Android appears java.lang.NoClassDefFoundError A solution to the error
- java.lang.IllegalArgumentException : could not get next sequenced ID for sequence name: Visitor solution
- Solution in idea java.lang.ClassNotFoundException : org.springframework.web . context.ContextLoaderListener