java中的复杂数据类型

java中的复杂数据类型,java,custom-data-type,Java,Custom Data Type,我设计了一个名为BingoCard的数据类型,它将创建一个随机的宾果卡。我试图将BingoCard生成一个数组,但在这一行中不断出现错误:System.out.println(CurrentCard[I].toString()) 我想知道我是否正确地创建了数组,还是做错了什么? 提前谢谢你的帮助 public class BingoGame { private int[] counter; private boolean done = false; private int numOfCards;

我设计了一个名为BingoCard的数据类型,它将创建一个随机的宾果卡。我试图将BingoCard生成一个数组,但在这一行中不断出现错误:System.out.println(CurrentCard[I].toString())

我想知道我是否正确地创建了数组,还是做错了什么? 提前谢谢你的帮助

public class BingoGame {
private int[] counter;
private boolean done = false;
private int numOfCards;
private int fastestCard;

public BingoGame(int num){
numOfCards = num;
counter = new int[numOfCards];
}


public int play(){
for(int a=0;a<numOfCards;a++){
    counter[a] = 0;
}

BingoCard[] CurrentCard = new BingoCard[numOfCards];
while(!done){
    for(int i=0;i<numOfCards;i++){
        System.out.println("This is the current card:");
        System.out.println(CurrentCard[i].toString());

        int currentNum = (int)(Math.random() * 75) + 1;
        counter[i]++;
        CurrentCard[i].currentNumber(currentNum);
        CurrentCard[i].bingo();
        if(CurrentCard[i].bingo()){
            done = true;
        }
        fastestCard = i;
    }

}
return counter[fastestCard];
}

}
公共类宾果游戏{
专用int[]计数器;
私有布尔完成=假;
私人智能卡;
私人int快捷卡;
公共宾戈加梅(整数){
numOfCards=num;
计数器=新整数[numOfCards];
}
公共int play(){

默认情况下,
对象
数组中的(int a=0;a元素为
null
。在尝试调用任何方法之前,需要实例化这些元素

for (int i = 0; i < numOfCards; i++) {
    currentCard[i] = new BingoCard();
    ...
}
for(int i=0;i
您创建了宾果卡数组,但没有初始化任何项。这就是为什么会出现空指针异常。

这是一个空指针异常