public class arraylst
{
static HashMap<String,List<String>>hm;
public static void main(String[] args)
{
hm.put("2",Arrays.asList("a","b","c"));
}
}
我不明白为什么这会导致 NullPointerException
。
有人可以帮帮我吗?
最佳答案
你需要设置hm
:
hm = new HashMap<String, List<String>>();
在你使用它之前。
关于java - 静态hashMap的空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8641039/