所以我正在研究处理卡片和卡片的实验室。我在deck.java中编写的代码应该初始化一个套牌。但是,我得到一个nullPointException,我不知道为什么。这是代码的一小部分(我在第#34; cards.add(thisCard)行中得到了错误;":
import java.util.List;
import java.util.ArrayList;
import java.lang.Math;
/**
* The Deck class represents a shuffled deck of cards.
* It provides several operations including
* initialize, shuffle, deal, and check if empty.
*/
public class Deck {
/**
* cards contains all the cards in the deck.
*/
private List<Card> cards;
/**
* size is the number of not-yet-dealt cards.
* Cards are dealt from the top (highest index) down.
* The next card to be dealt is at size - 1.
*/
private int size;
/**
* Creates a new <code>Deck</code> instance.<BR>
* It pairs each element of ranks with each element of suits,
* and produces one of the corresponding card.
* @param ranks is an array containing all of the card ranks.
* @param suits is an array containing all of the card suits.
* @param values is an array containing all of the card point values.
*/
public Deck(String[] ranks, String[] suits, int[] values) {
for (int i = 0; i < ranks.length; i++){
Card thisCard = new Card(ranks[i], suits[i], values[i]);
cards.add(thisCard);
}
size = cards.size();
shuffle();
}
}