目录
问题:
问题指向:
解决:
运行正常:
问题:
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null
at java.base/java.lang.reflect.Method.invoke(Method.java:570)
at org.myspringframework.core.ClassPathXmlApplicationContext.lambda$new$0(ClassPathXmlApplicationContext.java:172)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.myspringframework.core.ClassPathXmlApplicationContext.lambda$new$1(ClassPathXmlApplicationContext.java:83)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.myspringframework.core.ClassPathXmlApplicationContext.lambda$new$2(ClassPathXmlApplicationContext.java:69)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.myspringframework.core.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:43)
at com.dong.myspring.Test.Test.main(Test.java:10)
问题指向:
解决:
该问题是在一个空对象上调用方法而导致的,所以增加一个非空判断即可
if (singletonObject.get(ref) != null) {
setMethod.invoke(singletonObject.get(id), singletonObject.get(ref));
}
运行正常:
文章来源:https://www.toymoban.com/news/detail-732313.html
文章来源地址https://www.toymoban.com/news/detail-732313.html
到了这里,关于空指针异常:java.lang.NullPointerException: Cannot invoke “Object.getClass()“ because “obj“ is null的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!