Nid*_*ath 2 java properties hashmap
我正在尝试将地图放入属性中,putAll()并NullPointerException在我的地图不为空时获得一个
Map<String,Object> map = item.getProperties();
Properties props = new Properties();
if(map!=null) {
props.putAll(map); //NPE here
}
Run Code Online (Sandbox Code Playgroud)
的item.getProperties()回报Map<String,Object>,我想这些属性存储到属性文件。
我也尝试先实例化地图
Map<String,Object> map = new HashMap<String, Object>()
map = item.getProperties();
Properties props = new Properties();
if(map!=null) {
props.putAll(map); //NPE here
}
Run Code Online (Sandbox Code Playgroud)
我知道地图不为空,因为我可以在日志中看到地图值。
在Properties类扩展Hashtable其不接受null它的条目值。
任何非空对象都可以用作键或值。
如果您尝试放置一个null值,该Hashtable#put(Object, Object)方法会抛出一个NullPointerException. 有可能你的
map = item.getProperties();
Run Code Online (Sandbox Code Playgroud)
包含null值。