我的 BlackJack Java 游戏出现错误。错误是:
Exception in thread "main" java.lang.NullPointerException
at com.keegan.game.blackjack.Deck.createDeck(Deck.java:48)
at com.keegan.game.blackjack.Deck.<init>(Deck.java:33)
而且我对这段代码中的问题一无所知。谁能帮我理解错误告诉我的错误是什么?
这是代码Deck.java
:
public class Deck {
private ArrayList<Card> deck = new ArrayList<Card>();
private List<Card> cardUsed = new ArrayList<Card>();
Card c = new Card(null, null, null, 0);
public Deck(int numCards) {
this.createDeck(numCards, 4, null);
}
private void createDeck(int numCards, int numSuits, String[] cardRanks) {
deck = new ArrayList<Card>();
cardUsed = new ArrayList<Card>();
if ((numCards % numSuits) > 0) return;
for (int i=0; i < numSuits; i++) {
for(int j=1; j <= (numCards / numSuits); j++) {
deck.add(new Card(new Suit(i), cardRanks[j-1], cardRanks, j));
}
}
}
public Card dealCard( ) {
Card dealtCard = null;
if (deck.size() == 0){
deck.addAll(cardUsed);
this.shuffle();
cardUsed = new ArrayList<Card>();
}
dealtCard = deck.get(0);
deck.remove(0);
cardUsed.add(dealtCard);
return dealtCard;
}
public void shuffle() {
Collections.shuffle(deck);
}
public ArrayList<Card> getDeck() {
return deck;
}
public void setDeck(ArrayList<Card> deck) {
this.deck = deck;
}
public int getNumUsedCards() {
return cardUsed.size();
}
public List<Card> getCardUsed() {
return cardUsed;
}
public void setCardUsed(List<Card> cardUsed) {
this.cardUsed = cardUsed;
}