It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
已关闭8年。
这是我的代码:
我得到一个例外:
线程“主”中的异常java.lang.NullPointerException
在key.test.EnwikiOutlink.main(EnwikiOutlink.java:68)
该地图对象有10,000多个地图对象,我在服务器计算机上运行它并且无法调试。
但是,当我减小此地图的大小(小于10,000)时,程序运行正常。
问题的原因是什么,解决方案是什么?谢谢!
已关闭8年。
这是我的代码:
HashMap<String, HashSet<String>> map;
....// I didn't write those code that initial the map.
System.out.println(map.entrySet().size()); // run util here is ok, I get the size of the map.
for(Map.Entry<String, HashSet<String>> entry : map.entrySet()) {// here throw the exception
Sytem.out.println("abc");// didn't executed, throw exception before
}
我得到一个例外:
线程“主”中的异常java.lang.NullPointerException
在key.test.EnwikiOutlink.main(EnwikiOutlink.java:68)
该地图对象有10,000多个地图对象,我在服务器计算机上运行它并且无法调试。
但是,当我减小此地图的大小(小于10,000)时,程序运行正常。
问题的原因是什么,解决方案是什么?谢谢!
最佳答案
map
在哪里初始化?如果您实际上没有为其分配任何内容,则它当然是null
。
(尚不清楚它是类成员还是局部变量。)