Author
Java file is compiling but not running.
Rajesh Shekar
Greenhorn
Joined: Feb 25, 2012
Posts: 8
Hi All,
Im new to java and i wrote a new java program which will display hello world. I named the java file as Hello.Java and the file resides in my D drive. When i compiled it it worked fine. But when i try to run it i got an error as below,
Exception in thread "main" java.lang.NoClassDefFoundError : Hello
Can someone help me with this error?
Greg Brannon
Bartender
Joined: Oct 24, 2010
Posts: 530
Can we see the source code?
Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
Rajesh Shekar
Greenhorn
Joined: Feb 25, 2012
Posts: 8
Please find the code below
Greg Brannon
Bartender
Joined: Oct 24, 2010
Posts: 530
Is the name of the source file "Hello.java"? If not, it should be.
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted Feb 25, 2012 03:53:28
1
How are you running the code? The command should be something like "java -cp . Hello" while you are in the same directory as the Hello.class file.
Rajesh Shekar
Greenhorn
Joined: Feb 25, 2012
Posts: 8
Yes i run from command line what does cp means?
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted Feb 25, 2012 04:18:17
1
java cp option
Have you tried it?
Rajesh Shekar
Greenhorn
Joined: Feb 25, 2012
Posts: 8
Hi All,
Thanks a lot to all of the friends here after setting the class path my code worked fine.
subject: Java file is compiling but not running.