运行下一个代码时,出现错误“线程“main”java.lang.NullPointerException中的异常“
我认为这与deck[i2] 的填充有关我尝试做的是每次运行for循环时添加一个值。
有人可以告诉我出了什么问题吗?
public class Deck {
private Cards cards;
private String[] suits;
private String[] ranks;
private String[] deck;
private int i2;
public void Deck() {
//Instantiate class Cards
cards = new Cards();
//run method to get cards / suits
suits = cards.getSuits();
ranks = cards.getRanks();
//Build an array (deck) and fill it with all possible cards
i2 = 1;
for (int i = 0; i < suits.length; i++) {
//Run through ranks
for (int i1 = 0; i1 < ranks.length; i1++) {
deck[i2] = suits[i] + ranks[i1];
2++;
}
}
}
}