June 19th, 2004 11:06 PM
Ok, didn't know if this should go here or somewhere else... but I gots a problem thats happened twice now and I don't know what it is. I have the latest non beta Java SDK (j2sdk1.4.2_04) installed and I used to be able to compile things via batch scripts I made... they would be something like this:
But now everytime I run these batch files that worked before, I get this error:
And to answer any obvious questions, my programs do have a main method and they have compiled perfectly before and do so on different systems as well.
Exception in thread "main" java.lang.NoClassDefFoundError: Main
I've reinstalled Java three times and still haven't been able to get it work. The only way I am able to use Java at all is by installing the Netbeans IDE and using package statements in my code. This being the 2nd time this has happened since I started coding (fixed first time by formatting), I need some help?
- dave t
June 19th, 2004 11:18 PM
Well, the problem has been fixed by good ol' ZeroCool aka h3r3tic...
# Fix the CLASSPATH variable if, when running the code, you see a message like this one:
Exception in thread "main" java.lang.NoClassDefFoundError: MyHelloWorld
To set the CLASSPATH variable:
* Go to the Control Panel/System
* Change to the "Advanced" tab
* Click the button "Environment Variable" at the bottom of the dialog box
* Select CLASSPATH and click Edit
* Locate the "Variable Value" field. Add the following text at the end
The semicolon is a separator and the . tells the JVM to look for classes in your current directory.
June 19th, 2004 11:22 PM
"When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
"There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
"Mischief my ass, you are an unethical moron." - chsh
Blog of X
June 20th, 2004 12:45 AM
That sounds like a much better method than I was going to suggest :P I was just going to suggest running with the -classpath switch as in:
If you have any packages, you just add them after mydir separating each with a semicolon. But I would think that the above method suggested by Juridian is probably much easier/better.
java -classpath .\mydir myclass
I'm in the middle of writing a java program that will handle the creation of batch files for you, I'm just struggling with the design on the gui at the moment. As soon as I get a working version I'll post it to code review.