Debugging: interpreter issues


I'm getting a weird load of messages when I run the bytecode.

This is the interpreter complaining. In this case, the most usual error is this one...

Screenshot: Error - exception in thread

This is generated if the Classname and filename don't match, or you've passed the interpreter a file without a main block. You might also get this error if you try to run the ".java" file, not the ".class" file. Remember, the commands are...

javac TheClassname.java
java TheClassname

The final thing that might cause this error is if the Interpreter can't find the file. This is usually because the "classpath" hasn't been set up properly (this is where the JVM looks for the class files). You may also see this when compiling if you are using multiple classes...

Screenshot: Error - can't find symbol

There are two solutions to this. The first is to put the classpath into what you type to do the compilation and interpretation:

javac -classpath . TheClassname.java
java -classpath . TheClassname

The "." just means "look in this directory that I'm compiling from first". The alternative is to set up the classpath for the computer. You can find details of how to do this in the JDK tutorial. Remember to restart your command prompt after altering this variable or the new one won't be picked up.