2011-03-18 39 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认为,它可以帮助你开始编写代码,爸爸。