我一直得到错误:int无法解除引用。我如何解决它?

时间:2013-05-23 00:55:24

标签: java arrays int playing-cards

我开始编写War(卡片游戏)并且方法已经实例化了我需要知道为什么我会一直收到这些错误。

import java.util.*;

public class CardGame {
    public static void main(String[] args) {

        CardDeck CardDeckA = new CardDeck();
        //creates a standard card deck with 52 cards 1 - 10, J, Q, K, A diamond, spade, club, heart


        //Card( int value, int suit)

        int[] player1 = new int[52];
        int[] player2 = new int[52];
        int a = player1.length;
        int b = player2.length;

        for (int i = 0; a <= 26; i++) {
            player1[i].deal(); //Error: int cannot be dereferenced
            //deal( int n):Deals n cards from the top of the CardDeck, returns Card[]
        }

        for (int j = 0; a <= 26; j++) {
            player2[j].deal();//Error: int cannot be dereferenced
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您应该将方法称为

player = CardDeckA.deal(1)

而不是

player1[i].deal()

由于player1[i]是原始int,因此它没有方法。

deal会返回int[],具体取决于您使用它的方式,我怀疑它会类似于:

player = CardDeckA.deal(26)