Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main"

 
Angela lewis
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
 
Vlado Zajac
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
 
Elouise Kivineva
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 ]
 
Kalai Selvan
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.
 
Karthik shashikanth
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
 
Max Rahder
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic