2011-03-18 44 views
2

當我輸入一個簡單的代碼時,我得到一個我無法理解的錯誤代碼。Java不能找到類

的代碼是: 進口靜態文件java.lang.System.out;

類UseAccount { 公共靜態無效的主要(字串[] args) {

fred myAccount = new fred(); 
    fred yourAccount = new fred(); 

    myAccount.name = "Barry Burd"; 
    myAccount.address = "222 Cyberspace Lane"; 
    myAccount.balance = 24.02; 

    yourAccount.name = "Jane Q. Public"; 
    yourAccount.address = "111 Consumer Street"; 
    yourAccount.balance = 55.63; 

     myAccount.display(); 
     out.println(); 
     yourAccout.display(); 
} 

}

然而,當我嘗試編譯的代碼,我只是得到:

account2.java:9: cannot find symbol 
symbol : class fred 
location: class UseAccount 
     fred yourAccount = new fred(); 
     ^

我該如何解決這個錯誤?

我剛開始學習Java和這個代碼是直接從一個教程。根據教程使用「fred myAccount = new fred();」和「fred yourAccount = new fred();」確定了這些類,並且這部分代碼下面的信息填充了這些信息。

+0

你有一個類'fred'就是這裏訪問? – 2011-03-18 16:20:23

+0

你有沒有可以到達的地方'fred'?並請發佈完整的代碼,而不僅僅是一些片段。 – 2011-03-18 16:21:06

+0

你有沒有經歷過Java中的基本「Hello world」示例?對我來說,你的代碼看起來像C++ – bikashg 2011-03-18 16:21:19

回答

3

某處在你的代碼,你需要一個文件Fred.java(你應該使用大寫字母的名字,雖然Java不需要吧)有至少

class Fred { 
} 

,那麼你就需要填寫它來讓它做一些事情。

更重要的是,將類命名帳戶。

1

你需要使用編譯的類fred編譯類。

你有使用IDE認爲,它可以幫助你開始編寫代碼,爸爸。