• Post Reply Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError - What did I do wrong?  RSS feed

 
Ed Buckman
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a complete newbie... just started working on the Head First Java book and typed up the code on page 60 trying to figure out arrays. The error I get is:
Exception in thread "main" java.lang.NoClassDefFoundError: Dog
What am I doing wrong? It compiled without any errors and when I try to run it this is the error I get. Oh btw here is the code:
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ March 31, 2004: Message edited by: Dirk Schreckmann ]
 
Rikard Qvarforth
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi you need to add the keyword static to your main method. The main method should look like this
public static void main(String[] args)

the Java Virtual Machine �s looking for the main method signatue but cant find thats why tha exception is thrown. this is taken from the API
public class NoClassDefFoundError
extends LinkageError
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
Since:
JDK1.0

hope it helps !
//Rille
 
Nandini Sriram
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to Javaranch. Try setting the classpath to the directory in which the class file resides and also you might have to correct the 'main' method. It is "public static void main".
Regards
Nandini
 
Ed Buckman
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys... putting static in the main method and also moving the file to the directory defined as classpath helped make this thing run.
Phew... I was about ready to go insane. Love the Ranch
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!