Every beginner meets the same moment: you press Run, the screen fills with red text, and your first instinct is to close it and stare at your code instead.
Don't. The error message is the most useful thing on your screen. It was written by the people who built the language, and it usually tells you what went wrong and where. You just need to know where to look.
Here's a 3-step method that works the same way in Python, Java, JavaScript and SQL, with the most common beginner errors in each language as examples.
The 3-step method
- Read the last line first. That's the error type and the message: the what.
- Find the line number. That's the where. Look at that line, and if nothing is wrong there, look at the line just above it.
- Translate the message into a question about your code. "unsupported operand types
intandstr" becomes: "Which value on this line is text when I expected a number?"
That's it. Let's try it on real errors.
Python: the error is at the bottom
Here's a tiny program:
name = input("Your name? ") year = input("Born in? ") age = 2026 - year print("Hi", name, "- you are", age) Python answers with this:
Traceback (most recent call last): File "life.py", line 3, in <module> age = 2026 - year ~~~~~^~~~~~ TypeError: unsupported operand type(s) for -: 'int' and 'str' Step 1, the last line: TypeError: unsupported operand type(s) for -: 'int' and 'str'. You tried to subtract, and one side is a number (int) while the other is text (str).
Step 2, the line number: line 3, and newer Python versions even underline the exact spot with ^.
Step 3, the question: which value is text? year, because input() always gives you back text, even when someone types 1990. Convert it first: int(year).
👉 Full explanation, plus the other ways this error appears: Python TypeError: unsupported operand type(s) for 'int' and 'str'
Python also has errors that stop the program before it even starts, like this one:
File "loop.py", line 3 print(s) ^^^^^ IndentationError: expected an indented block after 'for' statement on line 2 Same method: the last line says what (Python expected an indented block), and the message even tells you where the problem started: the for on line 2. The line after it needs to be indented.
👉 Python IndentationError: expected an indented block after 'if', 'for' or a function
Java: the compiler stops you before you run
Java checks your code before it runs, so many errors show up at compile time:
Main.java:6: error: incompatible types: String cannot be converted to int int age = scanner.nextLine(); ^ Step 1: incompatible types: String cannot be converted to int. You're putting text into a box made for whole numbers.
Step 2: Main.java:6 means file Main.java, line 6. The ^ points at the value that doesn't fit.
Step 3: where does this value come from, and what type is it? nextLine() returns a String. Convert it with Integer.parseInt(...), or read a number directly.
👉 Java: incompatible types: String cannot be converted to int
Java's most famous runtime error works the same way. Newer Java versions spell out exactly what was null:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "..." is null Read it as a sentence: I couldn't call length(), because this variable was null. The question to ask: where should this variable have been given a value, and why wasn't it?
👉 Java NullPointerException: Cannot invoke ... because ... is null
JavaScript: open the browser console
In the browser, errors don't pop up on the page. Press F12 (or right-click → Inspect) and open the Console tab. One of the most common messages you'll find there:
Uncaught TypeError: Cannot read properties of null (reading 'addEventListener') Step 1: you tried to use .addEventListener on something that is null, meaning nothing.
Step 2: the console shows the file and line on the right. Click it to jump straight there.
Step 3: why is this element null? Usually document.querySelector(...) didn't find anything: the selector has a typo, or the script runs before the HTML element exists.
👉 JavaScript: Cannot read properties of null (reading 'addEventListener')
SQL: the last word is your clue
Database errors are short, but they still follow the pattern:
SELECT name FROM visitors WHERE room = Vault; Error: no such column: Vault Step 1: SQLite looked for a column called Vault.
Step 2: there's only one line here, so look at the word the message names.
Step 3: is Vault meant to be a column or a value? It's a value, the name of a room, so it needs single quotes: WHERE room = 'Vault'.
👉 SQLite error "no such column": usually missing quotes, plus 4 other causes
When you start counting and grouping rows, you'll meet a different kind of message, about aggregates and GROUP BY. The same 3 steps work:
👉 SQL GROUP BY errors: "misuse of aggregate" and "must appear in the GROUP BY clause"
And when there's no error at all?
The hardest bugs are the silent ones. CSS is the classic example: if a style doesn't apply, the browser doesn't complain at all. Then the method changes slightly: instead of reading a message, you inspect the element (F12 → Elements) and check which styles are crossed out and why.
👉 CSS not working? 7 reasons your styles don't apply
The same goes for code that runs but gives the wrong answer. No message will save you there. You compare what you expected with what you got, and work backwards.
Cheat sheet
| Language | Where the "what" is | Where the "where" is |
|---|---|---|
| Python | Last line of the traceback | File "...", line N just above it |
| Java | After error: or Exception: | File.java:N, or the first at ... line of the stack trace |
| JavaScript | The red line in the browser Console | File and line link on the right |
| SQL | The message itself, especially the name it mentions | The word or clause it names |
Practise reading errors, not just fixing them
The goal isn't to memorise every error. It's to stop being afraid of them. Next time something breaks, before you change a single character, say out loud: what went wrong, where, and what question that raises about your code.
If you're still choosing a first language, start here: Which programming language should you learn first? Python, JavaScript, SQL or Java
This article was first published on the Craftstack Academy blog. It was written with the help of AI.
