我对object2objectopenhashmap有一个问题,当我使用put方法时,java给我这个异常“nullpointerexception”。
代码如下:
private Object2ObjectOpenHashMap level1 = new Object2ObjectOpenHashMap();
private Object2ObjectOpenHashMap level0 = new Object2ObjectOpenHashMap();
public void map(Object ke, Text val, Context context) throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
int numberAttributes = conf.getInt("numberAttributes", 0);
String jsoncombinationlevel0 = conf.get("combinationlevel0");
String jsonopenlevel0 = conf.get("openlevel0");
String jsoncombinationlevel1 = conf.get("combinationlevel1");
ArrayList<OpenBitSet> open1ArrayList = new Gson().fromJson(val.toString(), new TypeToken<ArrayList<OpenBitSet>>(){}.getType());
ArrayList<OpenBitSet> open0ArrayList = new Gson().fromJson(jsonopenlevel0.toString(), new TypeToken<ArrayList<OpenBitSet>>(){}.getType());
ArrayList<CombinationHelper> chLevel0 = new Gson().fromJson(jsoncombinationlevel0.toString(), new TypeToken<ArrayList<CombinationHelper>>(){}.getType());
ArrayList<CombinationHelper> chLevel1 = new Gson().fromJson(jsoncombinationlevel1.toString(), new TypeToken<ArrayList<CombinationHelper>>(){}.getType());
//ricostruisco level1
int i=0;
for(OpenBitSet x : open1ArrayList) {
level1.put(x, chLevel1.get(i));
i++;
}
//other stuff
.
.
.}
所以,当代码到达for时,我使用put方法java给我一个异常:
Caused by: java.lang.NullPointerException at hadoop.InitializeCplusForLevelMapReduce$MapperInitializeCplusForLevel.map(InitializeCplusForLevelMapReduce.java:78)
78号线在哪
level1.put(x, chLevel1.get(i));
我不知道为什么,这似乎是正确的,我想创建level1,并为相对数组列表中的每个openbitset我想把它与相对combinationhelper放在level1。我只找到了方法,我试过其他方法,但都是一样的,一样的例外。
1条答案
按热度按时间nbysray51#
我想
chLevel1
为null,因为无法将字符串解析为对象类而且,你应该
new Gson()
一次,最好作为静电场