• Post Reply Bookmark Topic Watch Topic
  • New Topic

weird! No class definition found: -class name-  RSS feed

 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I�m so embarrassed to post this question, but
I have a class that contains only a main, in the main there is only System.out.println(�main�) ;

Java home is set, I can compile this class but when running it, it give me the error message:
No class definition found: <class name>
I use window, jdk1.4�
Every thing is right, for sure when running it.
Any ideas?
thanks
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NoClassDefFoundError always means that something is wrong with your class path.

Do you have the CLASSPATH environment variable set? If so, does it include the current directory (".")?

Try running your program like this:

java -cp . MyClassName
 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, it worked
 
Keith Swanson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simular problem, I installed the JDK, set the path and class path variables, I can compile the "hello world" program, but when I try to run I get the noclassdefinitionfound exception. using -cp did not work. any ideas?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Keith Swanson:
I have a simular problem, I installed the JDK, set the path and class path variables, I can compile the "hello world" program, but when I try to run I get the noclassdefinitionfound exception. using -cp did not work. any ideas?


Hi Keith,

Welcome to JavaRanch!

Note that it's "java space dash cp space dot space HelloWorld". Make sure all of those dots and spaces and things are in there. "-cp ." means "look for classes in the current directory" -- the dot represents the current directory.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Keith Swanson:
...I installed the JDK, set the path and class path variables...

At the "Hello World" stage, you're probably better off without having a system CLASSPATH at all.

If the CLASSPATH variable was already there for some other application, then you should probably keep it there, but make sure it includes the dot in the list of paths.

If you created the CLASSPATH variable as part of your Java installation, then I would suggest removing it entirely.

(Note: If you edit the system CLASSPATH, then you will need to open a new command prompt session to use the changes.)

Anyway, welcome to JavaRanch, and let us know how this goes!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kavi surulivel,
Your post was moved to a new topic.
New question, new topic.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!