David
David

Reputation: 14963

Why did i get this error?

here's the code:

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 ; 
    } 
}

here's the error:

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

What went wrong and why?

Upvotes: 0

Views: 125

Answers (3)

Ming-Tang
Ming-Tang

Reputation: 17659

How did you run the Java program in the command line, is it like this?

java Account.java

If yes, the remove the .java, because the java command takes a class name, not the file. The correct command is:

java Account

Also, make sure you compiled the file properly.

Upvotes: 5

Yishai
Yishai

Reputation: 91931

That error represents an error in your command line. Try

 java Acount

Not java Acount.java

Upvotes: 1

akf
akf

Reputation: 39505

It has to do with the way you are calling your class from the commandline. You shouldnt put the .java after your class name. try:

java -classpath . Account

Upvotes: 2

Related Questions