java - Why does this throw a NullPointerException? -


null pointer means there programmers error within paramter somwhere, code looked @ ensure haven't missed obvious?

it's simple % based poker bot, pretty sure here's "thinks" error is.

public action act(set<action> actions) {     random generator = new random();     int roll = generator.nextint(100) + 1; //gives number between 1 , 100     system.out.println("roll = " + roll);     action myaction = null;      if (roll <= 30) { // raise 30%         if (actions.contains(action.raise)) {             myaction = action.raise;         } else if (actions.contains(action.bet)) {             myaction = action.bet;         } else if (actions.contains(action.call)) {             myaction = action.call;         }     } else if (roll > 30 && roll <= 90) { // call/check 60%         if (actions.contains(action.call)) {             myaction = action.call;         } else if (actions.contains(action.check)) {             myaction = action.check;         }     } else if (roll > 90) { // fold 10%         if (actions.contains(action.fold)) {             myaction = action.fold;         }      return myaction; } 

}

edit:

heres added set action method:

public action act(set<action> actions, int minbet, int currentbet) {     action = client.act(actions);     switch (action) {         case check:             break;         case call:             betincrement = currentbet - bet;             if (betincrement > cash) {                 //todo: all-in partial call.                 betincrement = cash;             }             cash -= betincrement;             bet += betincrement;             break;         case bet:             betincrement = minbet;             if (betincrement >= cash) {                 //todo: all-in partial bet.                 betincrement = cash;             }             cash -= betincrement;             bet += betincrement;             raises++;             break;         case raise:             currentbet += minbet;             betincrement = currentbet - bet;             cash -= betincrement;             bet += betincrement;             raises++;             break;         case fold:             hand.removeallcards();             break;     }     return action; } 

the action method inherits interface class client.java:

action act(set<action> allowedactions); 

many thanks!

solution:

when try , run 2 of same bot against has conflict somewhere causing null pointer. when use 2 different bots plays fine no errors.

not clear getting npe bet on null input parameter

 set<action> actions 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -