[英]How to create Avro schema for Map<Integer,Map<Integer,Float>>?
[英]How to Initialize Map<Integer, Map<Integer, Float>>?
我想对Map<Integer, Map<Integer,Float>>
。 这是我初始化的方式:
Map<Integer, Map<Integer,Float>> map = new TreeMap<>();
for(int i=0; i<100; i++)
map.put(i, new TreeMap<>());
但是我总是为entrySet
获得null
。 当我尝试添加元素时
map.get(i).put(j.getKey(), d);
其中i
和j
是Map.Entry<Integer, Point3f>
,它什么也不做。 ( Point3f
是库vecmath
的对象)
编辑:我将其更改为HashMap
但现在我得到NullPointerException
。
老实说,我不确定为什么entrySet()
似乎为您返回null
,但是地图初始化似乎对我有用,对我来说还不错。
问题出在map.get(i).put(j.getKey(), d);
,对于您所说的i
和j
类型。 您将map
声明为Map<Integer, Map<Integer, Float>>
,这意味着map
具有Integer
键和Map<Integer, Float>
值。 因此,当您使用键i
为Map.Entry<Integer, Point3f>
调用get(i)
时, map
找不到与该特定键相对应的条目,因此它返回null
。 然后,当您尝试调用您认为已获得的地图上的put
时,会收到NullPointerException
。
Map<Integer, Map<Integer,Float>> map = new TreeMap<Integer, Map<Integer,Float>>();
Map<Integer,Float> f = map.get(5);
f.put(4,5.6f);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.