• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Exception in thread "main"  RSS feed

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have created a folder com. In this folder i have created the following file


I compile it using
D:\>javac com\Hello.java

But i am unable to run it. i get the following error
Exception in thread "main" java.lang.NoClassDefFoundError: com\Hello

when i do D:\>java com\Hello
Please help
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java parameter is fully qualified class name not file name so correct form is
d:\>java com.Hello

d:\>java com/Hello also works but not with \.
 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still getting error

D:\>java com.Hello
Exception in thread "main" java.lang.NoClassDefFoundError: com/Hello
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to comple the command is javac, not java.

What operating system are you using?

This link gives more info. about compiling under different operating systems and checking your java environment settings:
http://java.sun.com/docs/books/tutorial/rmi/compiling.html
 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Elouise Kivineva:
If you want to comple the command is javac, not java.

What operating system are you using?

This link gives more info. about compiling under different operating systems and checking your java environment settings:
http://java.sun.com/docs/books/tutorial/rmi/compiling.html



I am compiling it using

D:\>javac com\Hello.java

and it compiles fine.
i have a problem running it
I am doing
D:\>java com.Hello

and it gives the following error
Exception in thread "main" java.lang.NoClassDefFoundError: com/Hello

I am using windows 2000 pro
[ August 06, 2004: Message edited by: Angela lewis ]
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The problem may be with your classpath, check whether you have added
.(i.e current dir)in the classpath.

Kalai Selvan T.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI
Just try these steps

set classpath=%classpath%;.;
then run
java com.Hello

Hope this helps

cheers
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to have your .class file in a directory hierarchy that matches its package. In your case, you could manually create a directory "com" and move Hello.class there, or you could compile using the -d directory. When you use -d, the compiler will place the .class file in the proper directory hierarchy at the specified location. For example,
>javac -d . Hello.java
will result in the Hello.class being created in a newly created folder "com" located in your working directory.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!