About Us Contact Us Write for Us Advertise
Home > Java > Common Java Errors and How to Fix Them (Beginner Cheat Sheet)
Java

Common Java Errors and How to Fix Them (Beginner Cheat Sheet)

A quick-reference cheat sheet to the most common Java errors and their fixes: cannot find symbol, incompatible types, NullPointerException, ArrayIndexOutOfBounds, and silent logic bugs.

Shiv Pandey
Shiv Pandey
Oct 15, 2026 | 115 views
Common Java Errors and How to Fix Them (Beginner Cheat Sheet)

Every Java beginner meets the same set of errors over and over. The reassuring truth: once you recognise them, most take seconds to fix. This is your quick-reference cheat sheet to the most common Java errors — what each means and how to fix it — so you spend less time stuck and more time coding. Bookmark it for when the red text appears.

First, a mindset tip: errors aren't failures — they're Java telling you exactly what's wrong, usually with the file and line number. Read the message and the top line of the stack trace before anything else. Half of debugging is simply reading the error carefully.

Compile-time errors (won't even run)

"cannot find symbol"

Java doesn't recognise a name you used — usually a typo in a variable/method name, a missing import, or using a variable outside its scope. Fix: check spelling, add the import, and confirm the variable is declared and in scope.

"; expected" / "reached end of file while parsing"

A syntax slip — a missing semicolon, or unbalanced braces { }. The "end of file" one almost always means a missing closing }. Fix: check the line the error points to (and the one above it), and count your braces.

"incompatible types"

You assigned a value of the wrong type — e.g. putting a String into an int. Fix: match the types, or convert explicitly (e.g. Integer.parseInt(text)). Java's static typing catches these early, which is a good thing.

Runtime errors (compiles, then crashes)

Error Cause & fix
NullPointerException Used a null reference. Check for null / use Optional.
ArrayIndexOutOfBoundsException Accessed an invalid index. Remember indexes go 0…length-1.
NumberFormatException Parsed non-numeric text as a number. Validate input first.
ConcurrentModificationException Modified a collection while looping. Use removeIf.
ClassCastException Cast to the wrong type. Check the actual type first.
StackOverflowError Recursion with no reachable base case. Fix the base case.

ArrayIndexOutOfBoundsException — the off-by-one classic

int[] arr = {10, 20, 30};   // valid indexes: 0, 1, 2
arr[3];   // 💥 index 3 doesn't exist (length is 3, last index is 2)
// Fix: loop with i < arr.length, never i <= arr.length

The "it doesn't do what I want" category (no error at all)

The trickiest bugs throw no error — the code runs but produces the wrong result. The usual suspects:

  • Comparing objects with == instead of .equals() — the #1 silent bug.
  • Integer division surprises: 5 / 2 is 2, not 2.5 (use a double).
  • Off-by-one in loops (<= vs <).
  • Forgetting that Strings are immutable — s.toUpperCase() does nothing unless you reassign.

A simple debugging method

  1. Read the error message fully — it names the exception, the cause, and the line.
  2. Go to that line and ask "what could be wrong here?"
  3. Print or debug the values involved — is something null, empty, or unexpected?
  4. Search the exact error text if stuck — someone has hit it before.
  5. Change one thing at a time and re-test.

When I started, a red error message felt like a wall; now I see it as a signpost — it's literally telling me the file, the line, and often the exact variable at fault. The single habit that improved my debugging most was slowing down to read the whole error before touching anything, instead of panic-editing. Ninety percent of beginner errors are on this page, and each has a quick, mechanical fix. Bookmark this, get comfortable reading stack traces, and errors stop being scary — they become the fastest way to learn. Every developer, no matter how senior, reads errors all day. It's a core skill, not a sign you're doing it wrong.

Related

← Core Java course · Java interview questions →

Related Articles

Java Collections Cheat Sheet: Which to Use & How
Java

Java Collections Cheat Sheet: Which to Use & How

Java Cheat Sheet: Essential Syntax Quick Reference
Java

Java Cheat Sheet: Essential Syntax Quick Reference

How to Fix ConcurrentModificationException in Java (Beginner Guide)
Java

How to Fix ConcurrentModificationException in Java (Beginner Guide)

How to Fix NullPointerException in Java (Beginner Guide)
Java

How to Fix NullPointerException in Java (Beginner Guide)