Java:找不到符号?

时间:2011-12-25 14:28:23

标签: java compilation compiler-errors

当我尝试编译一个小程序时,我编写了一组卡片并打印它们,我得到6个错误,所有这些都是“找不到符号”的错误。有人可以查看我的代码并找到错误吗?感谢。

编译输出:

sudhakar@sudhakar-Dell-DXP061 ~/deck $ javac doDeck.java Deck.java Card.java
doDeck.java:7: cannot find symbol
symbol  : variable deck
location: class carddeck.Deck
        System.out.println(mydeck.deck[x].getRankString() + " of " + mydeck.deck[x].getSuitString());
                                 ^
doDeck.java:7: cannot find symbol
symbol  : variable deck
location: class carddeck.Deck
        System.out.println(mydeck.deck[x].getRankString() + " of " + mydeck.deck[x].getSuitString());
                                                                           ^
Deck.java:4: cannot find symbol
symbol  : variable deck
location: class carddeck.Deck
    deck = new Card[51];
    ^
Deck.java:10: cannot find symbol
symbol  : variable deck
location: class carddeck.Deck
            this.deck[cardcount] = new Card(suitit,rankit);
                ^
Deck.java:10: cannot find symbol
symbol  : variable cardcount
location: class carddeck.Deck
            this.deck[cardcount] = new Card(suitit,rankit);
                      ^
Deck.java:11: cannot find symbol
 symbol  : variable cardcount
location: class carddeck.Deck
                    cardcount++;
                    ^
6 errors

Deck.java:

package carddeck;
class Deck {
    public Deck () {
        deck = new Card[51];
        int cardcount = 0;
    }
     public void buildDeck () {
        for (Card.Rank rankit: Card.Rank.values()) {
            for (Card.Suit suitit: Card.Suit.values()) {
                this.deck[cardcount] = new Card(suitit,rankit);
                cardcount++;
            };
        };
    };
}

2 个答案:

答案 0 :(得分:1)

您的课程中没有属性deck,请尝试添加:

class Deck {
    private Card[] deck = null;
    public Deck () {
        deck = new Card[51];
        int cardcount = 0;
    }
//...
}

答案 1 :(得分:1)

你如何访问甲板,它没有定义。

class Deck {

Card deck;
int cardcount;
public Deck () {

    deck = new Card[51];
    cardcount = 0;
}

.....