布尔数组方法中的空指针异常

时间:2017-01-15 06:17:21

标签: java object methods nullpointerexception boolean

所以我一直在查看堆栈溢出,看看是否有任何问题已经回答了我的问题,但我觉得我的数组确实已经初始化了。目前我正在尝试制作简单的纸牌游戏,但无论我做什么,我都会继续犯同样的错误。

主:

public class Main {
public static void main(String[] args) {
    Dealer deal = new Dealer();
    User use = new User();
    Player play = null;
    Logistics log = new Logistics();

    boolean[] initElementList = {false, false, false};
    use.initElementList(initElementList);
    deal.initElementList(initElementList);

    while(play == null){
        use.printDeck();
        Card userChoice = use.chooseCard();
        Card dealerChoice = deal.chooseCard();
        **log.roundWinner(userChoice, dealerChoice);**
        play = log.gameWinner();
    }
    System.out.println(play);
}
}

物流:

public Card roundWinner(Card user, Card dealer){
    Dealer deal = new Dealer();
    User use = new User();
    String userChoiceE = user.getElement();
    String dealerChoiceE = dealer.getElement();

    int userChoiceS = user.getStrength();
    int dealerChoiceS = dealer.getStrength();

    **if(userChoiceE.equalsIgnoreCase("FIRE") && dealerChoiceE.equalsIgnoreCase("ICE")){
        use.setElementList(0);
        return user;
    }**

播放器:

public abstract class Player {

private boolean[] hasElement;
private Card[][] deck;

public boolean[] getElementList(){
    return this.hasElement;
}
**public void setElementList(int index){
    this.hasElement[index] = true;
} 
public void initElementList(boolean[] ElementList){
    this.hasElement = ElementList;
}**
public void createDeck(){
    CardGenerator cg = new CardGenerator();
    this.deck =  cg.Deck();
}
public Card[][] getDeck(){
    return this.deck;
}
}

0 个答案:

没有答案