• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java file is compiling but not running.

 
Rajesh Shekar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we see the source code?
 
Rajesh Shekar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find the code below
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the name of the source file "Hello.java"? If not, it should be.
 
Tim Moores
Bartender
Posts: 2755
38
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i run from command line what does cp means?
 
Tim Moores
Bartender
Posts: 2755
38
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java cp option

Have you tried it?
 
Rajesh Shekar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Thanks a lot to all of the friends here after setting the class path my code worked fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic