• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting error while running java program  RSS feed

 
abhi narkar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to compile and run simple print "Hello World!" program from command prompt. It compiles to create the.class file but when I run it I the following message appears:

Exception in thread "main" java.lang.NoClassDefFoundError: D:\George_Washington\Java\Test1\Test/class
Caused by: java.lang.ClassNotFoundException: D:\George_Washington\Java\Test1\Test.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: D:\George_Washington\Java\Test1\Test.class. Program will exit.

My code is as follows:



to compile I choose the jdk..\bin directory to be my working dir and use
>javac <path to .java file>

and run as
>java <path to .class file>

Cant understand whats going wrong. Am I missing any steps please help. (Also this program runs well in Eclipse IDE)

Thanks a lot!
~Abhi
 
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
Welcome to the Ranch!

It looks like you are typing a command like the following to run your program:

java Test.class

Leave of the .class - you have to specify the name of the class here, not the filename:

java Test

So, it is not "java <path to .class file>", but "java <fully-qualified name of the class>".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!