class SutdaDeck {
final int CARD_NUM=20;
SutdaCard[] cards = new SutdaCard[CARD_NUM];
SutdaDeck() {
cards[0].num=1;
}
}
class SutdaCard {
int num;
boolean isKwang;
SutdaCard() {
this(1,true);
}
SutdaCard(int num, boolean isKwang) {
this.num=num;
this.isKwang=isKwang;
}
public String toString() {
return num+(isKwang? "K" : "");
}
}
public class Main {
public static void main(String[] args) {
SutdaDeck deck = new SutdaDeck();
for(int i=0; i<deck.cards.length;i++)
System.out.print(deck.cards[i]+",");
}
}
5번쨰 줄에서 nullpointerexception이 뜨는데 왜 그런지 알려주실 분 있나요
cards 가 배열 초기화만 됬을 뿐이지 안에 내용물은 채워지지 않았으니까 cards[0]이 null이고 거기다가 num을 꺼내오려니 에러생기지
ㄳㄳ