填充树形图时出现空指针异常

时间:2015-10-23 09:07:41

标签: java dictionary nullpointerexception treemap

以下代码在尝试填充树形图时给出了一个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;
}

0 个答案:

没有答案