0

The following code gives me an nullpointer exception when trying to populate the treemap. More specifically at the line OpponentModel.put(OfferedUtil, OfferedBid); I can't seem to get this working whatever i try.

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;
}
fabian
  • 67,623
  • 12
  • 74
  • 102
  • Try to use a debugger to check what value is null. – SomeJavaGuy Oct 23 '15 at 09:08
  • 1
    If the then clause of the if is executed a NPE is **guarantied** (unless another thread is writing to that field between the check for `null` and the method call). – fabian Oct 23 '15 at 09:16

0 Answers0