所以我的問題只是我得到一個Nullpointerexception
當測試創建數組,並不能找出原因:( 它想要更多的文字,所以我正在做的是試圖使甲板卡如u很可能會看到,我使用JUnit測試陣列的創建,但我得到的失敗。我得到一個nullpointerexception請幫助:)
的例外是在IF語句。
public class Deck {
private int type;
private int text;
private String[] texts;
private String[] types;
private CardMaster[] deck = new CardMaster[38];
public CardMaster[] getDeck() {
return deck;
}
public void setDeck(CardMaster[] deck) {
this.deck = deck;
}
public Deck()
{
for(int i = 0;i<deck.length;i++)
{
int id;
Random Rgen = new Random();
id = Rgen.nextInt(deck.length+1);
do
{
if (deck[id].equals(null))
{
deck[id] = new CardMaster("test");
}
}
while(!deck[id].equals(null));
}
}
在哪一行?你的堆棧跟蹤在哪裏? – A4L
有些東西需要初始化。'deck [id]'沒有被初始化。默認值是'null'。 – Maroun
你能否改變標題? –