为什么我会收到此错误?

时间:2010-04-09 01:49:10

标签: java

这是代码:

class Acount
{ int sum ; String owner ; //these seem to make sense 
    //a constructor or two 
    public Acount () 
    { this.sum = 0 ; this.owner = "John Doe" ; }

    public Acount (String name) 
    {this.sum = 0 ; this.owner = name ; } 

    public Acount (String name, int sum) 
    {this.sum = sum ; this.owner = name ; } 

    //prints an acount in the format "owner" "sum" 
    public static void printAcount (Acount Acount) 
    {System.out.print (Acount.owner) ; System.out.print (" ") ; System.out.println (Acount.sum) ; } 

    public static void main (String[]arg) 
    { 
        Acount Acount1 = new Acount ("david", 100) ; 
        System.out.println ("heres the first acount as it was created:") ; 
        printAcount (Acount1) ; 
        System.out.println ("now i changed one of its instance varaibles with a static method") ; 
        upOne (Acount1) ; 
        printAcount (Acount1) ; 
    } 

    public static Acount upOne (Acount Acount)
    { 
        Acount.sum = Acount.sum + 1 ; 
        return Acount ; 
    } 
}

这是错误:

Exception in thread "main" java.lang.NoClassDefFoundError: Acount/java

出了什么问题,为什么?

3 个答案:

答案 0 :(得分:4)

你是如何在命令行中运行Java程序的?是这样的吗?

java Account.java

如果是,则删除.java,因为java命令采用类名而不是文件。 正确的命令是:

java Account

另外,请确保正确编译文件。

答案 1 :(得分:2)

它与您从命令行调用类的方式有关。你不应该把.java放在你的班级名之后。尝试:

java -classpath . Account

答案 2 :(得分:1)

该错误表示命令行中的错误。尝试

 java Acount

不是java Acount.java