This page only tells you what your error message means--not how to fix
it. That will depend on what you intended your code to do.
Don't attempt to fix your code until you understand why it's broken.
These errors are often caused by very small mistakes that are easy to
miss, so there's no shame in having someone else help you find the
mistake.
Error Message | What It Usually Means |
---|---|
something expected | The parser was surprised by a symbol you wrote at or just before this point. |
cannot find symbol -- class | Make sure that file is saved in the same folder as the file that refers to it. |
cannot find symbol -- method | You got the method name wrong, or you called it on the wrong file/class. |
class, interface, or enum expected | You have too many closing braces. |
class is public, should be declared in a file named | Your class name and file name must match exactly. |
illegal start of expression | You're missing a closing brace for the previous method declaration. |
illegal start of type | You wrote a statement that does not appear inside a method body. |
incompatible types -- expected type | Make sure you understand why it found what it did, and why it expected what it did. |
missing method body | Your method declaration line has a semicolon. |
missing return statement | The compiler found a pathway through your non-void method that does not reach a return statement. |
non-static method cannot be referenced from a static context | You called a method on a class name, instead of on a specific instance of that class. |
possible loss of precision | You assigned a double value to an int variable. |
reached end of file while parsing | You're missing a closing brace at the end of the file. |
unexpected type -- required variable | You used = instead of ==. |
unreachable statement | You wrote this statement after a return statement. Remember that return statements return from the method immediately. |
variable might not have been initialized | The compiler found a pathway through your method where you access the value of a variable before you've assigned anything to it. |
Error Message | What It Usually Means |
---|---|
My program freezes. | You have a loop that never reaches its stopping condition. |
ArrayIndexOutOfBoundsException | You tried to access an array element with an index that was too high or too low. |
NullPointerException | Look for every period (.) or open bracket ([) on the line of code that caused the error. Something immediately to the left of one of these periods/brackets must have been the null value (instead of being the object or array you thought you had). |
OutOfMemoryError | You are constructing new objects inside an infinite loop. |
StackOverflowError | You have an infinite recursion. In other words, your method calls itself, which then calls itself, without ever stopping. |
StringIndexOutOfBoundsException | You tried to access a character in a String with an index that was too high or too low. |
java.lang.RuntimeException: Attempt to move robot from (4, 2) to occupied location (4, 3) at Robot.move(Robot.java:80) at Lesson.climbOneStair(Lesson.java:13) at Lesson.climbAllStairs(Lesson.java:7)Clearly, this error message is telling us that we told the robot to move into a wall (and it even tells us where the robot and the wall are), but there's a lot more we can learn from reading the rest of the message. Run-time error messages should be read from the bottom up. According to this error message, we called the climbAllStairs method, which, on line 7 of Lesson.java, called the climbOneStair method, which, on line 13 of Lesson.java, called the move method, which crashed on line 80 of Robot.java, when the robot tried to move into a wall.
Now, we might guess that the bug is in move, since that's
where the program crashed. But we probably trust that the
move method has been carefully tested, so we must have called
move in an inappropriate manner. Specifically, we must have
violated the move method's precondition, by calling
move when the front of the robot was blocked. So, we back
up to line 13 of Lesson.java, where we called the move
method. Now we need to step back and think. Was
climbOneStair correct in calling move? If not, we
should fix the bug in climbOneStair But if
climbOneStair was correct, maybe we called
climbOneStair when we shouldn't have, and the bug is in
climbAllStairs ...