Having Problems Running my Java Progs
Hey guys,
I keep getting the following error message when I try to run any of my java programs.
Exception in thread "main"
java.lang.NoClassDefFoundError: HelloApp
this is the app that im trying to run;
publicclass HelloApp
{
publicstaticvoid main (String[] args)
{
System.out.println("Hello, World");
}
}
I cant see anything wrong with this piece of code. Ive definately saved the code as HelloApp.java. I've tried several different programs all with the same result. Does anyone have any ideas on why this is happening?
Thank You
Jaz
[925 byte] By [
Jazmana] at [2007-10-3 9:51:04]

Have you compiled it?
If not, you need to type
javac HelloApp.java
and press enter.
this will produce a class file named HelloApp.class
You can then run it by typing
java HelloApp
and pressing enter.
Now, if you were already compiling it, then you may have a classpath issue.
BobCa at 2007-7-15 5:08:21 >

Yes I have compiled it and I have the class file to prove it. As far as the class path problem is concerned, i've just checked now and I can see that I've pointed the path, in the environment variables, to the bin directory in the jdk folder.
yes, but you need to set the CLASSPATH variable to the location where you are executing your .Class files. I.e. CLASSPATH=C:\java\classes;etc.Or, when you execute the program, use the -cp argument:java -cp . HelloAppwhere the . indicates the current directory.
OK, classpath is different from path, it's specifically used by java to locate .class files.
Apparently some Windoze versions do not automatically include the local directory in the classpath - or may not have a classpath variable set until you do it manually.
So, the easiest way to see if this is your problem is to set the classpath in the command line like so:
java -cp C:\WhereIHidMyFiles HelloApp
(obviously, substitute the correct directory name above)
BobCa at 2007-7-15 5:08:21 >

I have tried exactly as you have written (obviously substituting for my own directory) and I get the following message;
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
and then a load of options. Am I missing an argument or something?