Weird Java errors
PGSS Computer Science Core
Sometimes the error messages the Java compiler gives aren't
entirely self-explanatory. This is a list of some error messages,
with a description of what it probably means. If you discover a new
error message that doesn't make sense, contact me; we'll find the
solution and put a description here too.
- Can't find class ``x''
- Go to Project Settings under the Edit menu, and select Java
Project. The text in the ``Main Class'' field should contain the name
of the class you're using. (If you're editing Prime.java, the class is
Prime; if you're editing AddBigNumbers.java, the class is
AddBigNumbers.)
- Could not create output file (possibly you're running Metrowerks Java?)
- You're running Metrowerks Java. Go to the far right-hand menu and
select Metrowerks Java to enter that application. Then select Quit from
the File menu. This will return you to the CodeWarrior IDE. Now
try compiling again.
- Exception in thread...
- Look at the word at the end of the first line. This is the
exception name. Look it up
under Exceptions below. For example, the
relevant word for the following line
Exception in thread "AWT-macos" java.lang.ArrayIndexOutOfBoundsException: 2
is ArrayIndexOutOfBoundsException.
- Identifier expected
- If the problem is with a function that you're trying to add to the
program, you should place the function within the braces after
``class AddBigNumbers'' (or whatever class the file you're
looking at defines).
This means that the function definition should come just before the
definition of the function you're supposed to write.
- KeyServer not found
- The problem is not yours; the computer you're using is at fault.
Try using another computer. If it still doesn't work, use yet another
computer. If this doesn't work, well, find a person running
the cluster and see what they can say about it.
- The droplet cannot launch because it can't launch
Metrowerks Java.
- Quit all applications but Finder and CodeWarrior IDE. (You can
reach these through the far right-hand menu.)
Exceptions
- ArrayIndexOutOfBoundsException
- You are attempting to access an array at an index that doesn't
exist. Remember a Java array arr is numbered from 0 to
arr.length - 1. You are probably accessing
arr[arr.length]. Exactly which index of the array you're
illegally accessing is revealed by the number immediately following
the colon after the exception name.