Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFound error

 
Kondapally Ashwin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting a runtime exception when I try to run any java program after compiling it. The message I am getting is

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld.

I have set the path to set path = C:\j2sdk1.4.2_07\bin; and classpath to set classpath = .;C:\j2sdk1.4.2_07\lib;. I have even tried to place the program in the bin folder of j2sdk1.4.2_07 but am still getting the same exception.

Please advise.

Thanks,
Ashwin.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you're having trouble running it. Did you have success compiling it? It must be compiled before it is run.

javac HelloWorld.java

Then you can run it with the java command

java HelloWorld

Here's a multimedia tutorial for you that shows you exactly how to write, compile and run a HelloWorld.java file using the JDK.

http://www.technicalfacilitation.com/examscam/get.php?link=../scja/multimedia/writecompilerunsdk

Good luck!

-Cameron
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you've set CLASSPATH, and set it wrong, then Kameron's instructions won't work; I suspect that's already what you're trying. What you need to do is quickly tell java to ignore whatever you've set as the CLASSPATH, and the easiest way to do that is to specify a value on the command line. So try

java -cp . HelloWorld

That's java space dash cp space dot space HelloWorld.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Assume you are in d:\hw directory, and source file name is Hello.java

Then from d:\hw directory,

javac Hello.java
set CLASSPATH=.;%CLASSPATH%
java Hello

& One More thing , if your source file is having package then, assume
the package is

package com.hw;

Then

javac -d . Hello.java
set CLASSPATH=.;%CLASSPATH%
java com.hw.Hello

or

java -cp . com.hw.Hello
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15483
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kondapally Ashwin:
H... and classpath to set classpath = .;C:\j2sdk1.4.2_07\lib;.

You do not need to include the lib directory of the JDK into the classpath.

Just make sure that the CLASSPATH variable is not set at all. If it is not set, Java by default looks for classes in the current directory.

More info: How Classes are Found
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic