Something Simple I'm Sure
I am trying to wite a program that writes to a file. It compiles fine, but when it runs I get
Exception in thread "main" java.lang.NoClassDefFoundError
heres the code:
import java.io.*;
public class Snap
{
public static void main( String[] args){
try{
BufferedWriter out = new BufferedWriter(new FileWriter
("checkForsnap.bat"));
for(int n = 0000;n<10000;n++){
out.write("ping snap" + n);
out.close();
}
}catch (IOException e){
}
}
}
[549 byte] By [
james3302a] at [2007-11-27 6:52:12]

> how about that if I move that class file into
> c:\program files\java\jdk1.6.0\bin it works.
Don't do that. It's like pushing the gas harder so that your car will move even with the parking brake on.
> I have
> set my PATH environment variable to that path and it
> says javac in an unrecognized command when I run it
> from anywhere else
If your PATH includes the directory where javac.exe is, then you won't get "unrecognized command" (but you'll have to start a new command window after you change it in the control panel).
PATH has NOTHING to do with the ClassNotFoundException.
[url=http://wiki.java.net/bin/view/Javapedia/ClassPath]Javapedia: Classpath[/url]
[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html]How Classes are Found[/url]
[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html]Setting the class path (Windows)[/url]
[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html]Setting the class path (Solaris/Linux)[/url]
[url=http://www-106.ibm.com/developerworks/edu/j-dw-javaclass-i.html]Understanding the Java ClassLoader[/url]
java -cp .;<any other directories or jars> YourClassName
You get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
javac -classpath .;<any additional jar files or directories> YourClassName.java
You get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
jverda at 2007-7-12 18:26:40 >
