Java Error with All of the .bat Programs

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Java Error with All of the .bat Programs

Firephyz
Let me start by listing my specs:
Windows 7 Ultimate 64-bit SP1
Java 7 Update 45

When I try to run the .bat programs like the HardwareSimulator.bat, I always get a java error. A black console screen would appear and then disappear just a split second later. The only way I could read the errors was if I captured my screen and looked at the video frame by frame. At first, I had to direct the .bat file to where my java.exe program was located. After this, however, another problem appeared and the error reads: Exception in thread "main" java.land.NoClassDefFoundError: HardwareSimulatorMain. I have tried running with administrator but it still won't work. Strangely, however, the programs do seem to work if I run them on a virtual windows 7 machine. Any help would be greatly appriciated.
Reply | Threaded
Open this post in threaded view
|

Re: Java Error with All of the .bat Programs

jmogarrio
I don't know if you're still having this problem, but I did, so I'll give some tips for troubleshooting for anyone past, present or future who might have this problem.

First, to be able to easily read the error message, run the batch file in a command prompt window. You can Shift + Right Click on the blank space of the explorer window and you should see an option that says "Open command window here" (or you can just navigate to the directory in an already open window). Now type the name of the desired file, say, HardwareSimulator.

There are two errors one might expect to see. One, which you wouldn't expect if you generally work with Java, would read something like "'java' is not recognized as an internal or external command, operable program or batch file." This means Windows can't find java.exe in the current directory, which you really shouldn't expect it to, and moreover your PATH environment variable doesn't include the directory where the program is contained. If this makes no sense to you and need help to figure out how to fix it, visit this link.

The likeliest error is "Error: Could not find or load main class", but there's oodles of ways this could come up. The way it did for me was "Error: Could not find or load main class <part of some directory>;.;bin.classes;bin.lib.Hack.jar;bin.lib.HackGUI.jar;bin.lib.Simulators.jar;bin.lib.SimulatorsGUI.jar;bin.lib.Compilers.jar". You might also just see part of a directory name. This would happen if you had a directory in your CLASSPATH environment variable surrounded by quotation marks, followed at some point by a whitespace. There are multiple ways to fix this.

First, you can remove the quotation marks in your classpath variable. They don't seem to be necessary: follow the link I posted above if you don't know how. Second, you can open the batch file in a text editor and copy the main command: everything from "java" down to the class name, which should be the last word before the "%1" characters. Open a command window in the same directory, then paste the command, but before you click enter, delete the bit that reads "%CLASSPATH%" (NOT the one that reads "-classpath"). Alternatively, you can just delete that bit in the batch file and save it before you run it.

I can't imagine any other sort of error to be likely, barring the possibility that you messed with the directories in nand2tetris or that your JRE isn't properly installed or updated. Should none of this help it's probably better to post the exact text of your error message.