可能重複:
When traverse a HashMap, I get NullPointerException一個HashMap的遍歷,我得到NullPointerException異常
這是我的代碼:
HashMap<String, HashSet<String>> map;
....//I didn't write those code.
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
}
我得到異常:
線程中的異常「main」java.lang.NullPointerException在key.test.EnwikiOutlink.main(EnwikiOutlink.java:68)
映射對象有超過10,000個映射對象,我在服務器機器上運行它並且無法調試。但是,當我縮小這張地圖的尺寸(小於10,000)時,程序運行正常。問題的原因是什麼,解決方案是什麼?謝謝!
所以'System.out'和for循環之間沒有任何內容?你肯定會得到NPE的線路? – Thomas 2012-04-13 11:58:37