以下代码在尝试填充树形图时给出了一个nullpointer异常。更具体地说,在OpponentModel.put(OfferedUtil, OfferedBid);
行,无论我尝试什么,我似乎都无法工作。
public TreeMap<Double ,Bid> updateOpponentModel(Double OfferedUtil, Bid OfferedBid)
{
if (OpponentModel==null){
OpponentModel.put(OfferedUtil, OfferedBid);
}
else if ( OpponentModel.size()< 5 || OpponentModel.firstEntry().getKey()<OfferedUtil) {
if ( OpponentModel.size() == 5){
OpponentModel.remove(OpponentModel.firstEntry());
}
OpponentModel.put(OfferedUtil, OfferedBid);
//System.out.println("Updated Opponent Model utility:" +OpponentModel.firstEntry().getKey());
//System.out.println("With utility:" + OfferedUtil);
}
//System.out.println("check size: "+ OpponentModel.size());
return OpponentModel;
}