| Author |
NoClassDefFound error
|
Kondapally Ashwin
Greenhorn
Joined: May 16, 2006
Posts: 25
|
|
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
Joined: Aug 26, 2006
Posts: 4967
|
|
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
|
Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24056
|
|
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.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Srinivas Kalvala
Ranch Hand
Joined: Oct 20, 2005
Posts: 257
|
|
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
Bartender
Joined: Aug 16, 2005
Posts: 12921
|
|
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
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: NoClassDefFound error
|
|
|