Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Getting error while running java program

 
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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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>".
 
I am going to test your electrical conductivity with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic