Compile Time Errors
The Java compiler does a lot of checking for you, and produces a lot of
compile time error messages. Although you may find this irritating at first,
if you are not used to it, it is a very good thing. Compile time errors are a
lot easier to deal with than run time errors. Here are a few tips for dealing
with them.
- When you get a lot of error messages from the compiler, don't panic,
it is normal.
- Just concentrate on the first error message, because most of the
rest are probably just knock-on effects, where the compiler hasn't been able to
"recover".
- The error message will give you a line number, and a position within the
line, so you can go to that line in your editor.
- The position given is the first point where the compiler cannot continue,
so the error is guaranteed to be before that point.
- Very often, e.g. where there is a missing semicolon, the error is on the
line before the one reported, and sometimes even further back.
- Don't be surprised if you can't understand the error message which
the compiler gives you, because the compiler can only report the error from its
point of view using compiler jargon, not from your point of view.
- Still, it is often possible to pick up clues from the error message,
even if you don't really understand it.
- At a pinch, you may be able to use trial and error to narrow down
the problem, by making small changes to your program and recompiling.
- If you have made a serious attempt to find the problem and can't, ask
someone rather than wasting hours.
- Afterwards, work out how you could have spotted it quickly yourself,
to make sure you will recognise the problem if you ever meet it again.
These hints work with any language and any compiler. It isn't sensible to
list possible error messages, because they differ between compilers and between
versions of one compiler. But for any one compiler version, there aren't all
that many that you are likely to meet, so you will soon get used to them.
It is also definitely not sensible to try to list the possible causes of the
errors, because there are too many possibilities and every beginner has their
own ingenious errors,