我有一个 ArrayLists 的 HashMap 值,但是当我添加 ArrayLists 时 HashMap 保持为空,然后当我尝试 get() ArrayList 时抛出 NullPointerException。很迷茫。
Random rand = new Random();
HashMap<String,ArrayList<Integer>> hands = new HashMap<String,ArrayList<Integer>>();
HashMap<Integer, Boolean> deck = new HashMap<Integer, Boolean>();
for(int x=0;x<4;x++){
for(int y=0;y<4;y++){
hands.put(x+SUITS[x], new ArrayList<Integer>());
}
}
for(int x=0;x<4;x++){
for(int y=0;y<13;y++){
int randCard = rand.nextInt(52)+1;
if(!deck.containsKey(randCard)){
deck.put(randCard, true);
hands.get(x+cardSuit(randCard)).add(randCard);
}else y--;
}
}