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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Getting error while running java program

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
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!
Java Cowboy
Posts: 16084
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
    Bookmark Topic Watch Topic
  • New Topic