Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Running compiled code  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just testing the installation of java on my machine. I wrote the following program and saved it as Hello.java. Then I compiled it using javac Hello.java. It compiles fine. But when I try to run it using java Hello I got the following error messageException in thread "main" java.lang.NoClassDefFoundError: Hello
My code sample for Hello
-------------------------
public class Hello {
public static void main (String[] args){
System.out.println("Hello World!");
}
}
What is wrong. Thanks for help.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amar, you need to set your classpath so that it points to the directroy of your Hello.class file.
you can do this easily from the DOS
let us assume that your Hello.class file is in the following directory
C:\Amar\classes\Hello.class
then you set the path in the dos like this way
C:\>set classpath=%classpath%;c:\Amar\classes
and then you can run the class using <java Hello>
if your class is inside a package, you follow the same step
and point to the directory of your package.
Hope this can help
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Amar Das:
I was just testing the installation of java on my machine. I wrote the following program and saved it as Hello.java. Then I compiled it using javac Hello.java. It compiles fine. But when I try to run it using java Hello I got the following error messageException in thread "main" java.lang.NoClassDefFoundError: Hello
My code sample for Hello


after compilling see the directory listing of your current directory in which your class hello existing.
read the name of that class carefully with propercase (upper/lower) and then execute command
java "your class name wihout extension"
every thing will be fine.
this is the mistake due to uppercase lowercase mistake & nothing else.
check name of the .class file created after compillation and then execute above command
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!