Reading errors without fear
Errors are not a sign you are doing badly — they are the normal working conditions of every programmer alive. This lesson teaches you to read a Kotlin error, a Gradle failure and a crash, and to know which one you are looking at.
The skill nobody tells you about
Here is something that would have saved most beginners a lot of misery if someone had said it on day one:
Professional developers see errors constantly. Dozens a day. Red text is not an exam result and it is not a verdict on you. It is the normal texture of the work — the machine noticing something before it becomes a problem, and telling you where.
The difference between someone who finds coding fun and someone who finds it crushing is almost never talent. It is whether they read the error or panic at the sight of it.
By the end of this lesson you will be able to look at any red block and answer three questions in about ten seconds: which kind of error is this, which file, which line. That is the whole skill. Everything after it is just fixing.
Think about a letter coming back from the post office.
There is a sticker on it. The sticker does not say you are bad at addresses. It says "no such street number at this postcode" — precisely which part is wrong, and precisely where it stopped.
It cannot tell you what you meant to write, because it does not know your friend. But it has narrowed a huge problem down to one line of the address, and that is enormously useful.
Every error message you will ever see is that sticker. It is not a judgement. It is a location.
Three kinds of error, in the order you meet them
You will meet them in a fixed sequence, and knowing which one you are looking at tells you where to go next.
| # | Where it appears | When | What it means | |||
|---|---|---|---|---|---|---|
| 1 | Red underline in the Editor | As you type | The already knows this line is wrong. | |||
| 2 | Red text in the Build panel | When you press Run | A [[compile-error | build error]] — no APK was produced. | ||
| 3 | The app closes; text in [[logcat | Logcat]] | While the app runs | A [[runtime-error | runtime error]] — a [[crash | crash]]. |
The distinction between 2 and 3 is the important one, and it is worth being precise about.
A build error means your code could not be turned into an app. Nothing was installed; whatever is on your phone is still the previous version. The compiler caught it.
A runtime error means your code built perfectly, installed perfectly, ran, and then hit a situation it had no answer for — dividing by zero, asking for the fourth item of a three-item list. The compiler could not have known, because it depends on what actually happens.
Build errors are the friendly kind. You want as many of your mistakes as possible to be build errors, which is a large part of why Kotlin is designed the way it is.
Anatomy 1 — a Kotlin error line
This is the format you will see most often. Every part of it is doing a job.
1e: MainActivity.kt:24:19 Unresolved reference 'nam'.
2^ ^ ^ ^ ^
3| | | | └ what is wrong
4| | | └ column 19
5| | └ line 24
6| └ which file
7└ e: = error (w: = warning)Read it right to left and it becomes a sentence: there is a word here nobody has defined; it is called nam; it is 19 characters along line 24 of MainActivity.kt.
The column number is the part most people ignore, and it is the most useful part on a phone. Line 24 might be long. Column 19 is a single word.
e: is an error and stops the build. w: is a and does not.
A build can produce fifty w: lines and still end in BUILD SUCCESSFUL. Warnings are the compiler saying "this is legal, but are you sure?" — worth reading later, never worth panicking about now.
Anatomy 2 — a Gradle failure block
When the build fails, the last thing on screen is not your error. It is this:
1FAILURE: Build failed with an exception.
2
3* What went wrong:
4Execution failed for task ':app:compileDebugKotlin'.
5> A failure occurred while executing
6 org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
7 > Compilation error. See log for more details
8
9* Try:
10> Run with --stacktrace option to get the stack trace.
11> Run with --info or --debug option to get more log output.
12
13BUILD FAILED in 38sRead that carefully and notice what it does not contain: any mention of your code.
This block tells you which task failed, not what is wrong. :app:compileDebugKotlin means "the step that compiles your Kotlin". So the real message — the e: line with your file and line number — is further up the log, printed before this summary.
This is the single most common way beginners get stuck: they read the bottom of the log, find nothing useful, and conclude the error is unreadable. Scroll up. It is always up.
Two task names worth recognising, because they tell you which half of the project is unhappy:
:app:compileDebugKotlin— your Kotlin. Look fore:lines above.:app:processDebugResources— yourres/folder. Look forAAPT: error:above.
Anatomy 3 — a crash
Your app builds, installs, opens, and then vanishes back to the home screen. Open and you will find something like this:
1FATAL EXCEPTION: main
2Process: com.yourname.hellopocket, PID: 12043
3java.lang.IndexOutOfBoundsException:
4 Index 3 out of bounds for length 3
5 at com.yourname.hellopocket.Greeting(MainActivity.kt:26)
6 at com.yourname.hellopocket.MainActivityKt.render
7 at androidx.compose.runtime.ComposerImpl.doCompose
8 at android.app.ActivityThread.main(ActivityThread.java:8757)Four parts:
FATAL EXCEPTION: main— the app has stopped. "main" is the thread the screen runs on.- The type and message —
IndexOutOfBoundsException, and helpfullyIndex 3 out of bounds for length 3. You asked for item 3 of a list that only has items 0, 1 and 2. - The — the trail of function calls that led here, most recent first.
- The line that matters — the topmost line containing your own package name. Here that is
com.yourname.hellopocket.Greeting(MainActivity.kt:26).
Everything below your line is Android's own machinery. It is not broken. It is just the road your mistake travelled down.
A stack trace can be forty lines long and it is tempting to read none of it. Do not skip it — scan it. You are looking for one thing only: the first line with your package name and a .kt file with a number after it. That is your bug's address.
The three rules
1. Read the first error, not the last.
One missing brace can produce eighteen errors, because the compiler carries on trying to make sense of a file that stopped making sense at line 12. Errors two through eighteen are consequences. Fix number one and rebuild — most of the rest disappear with it.
2. Find your own file name.
If a message mentions androidx, kotlin.jvm or android.app, it is describing where your mistake landed, not where you made it. Keep scanning for a file you wrote.
3. Change one thing, then rebuild.
Two changes at once, and a fixed build tells you nothing about which one helped. This matters more here than on a laptop, because each build costs you real minutes and a slot from your allowance.
When you genuinely cannot tell
A short checklist that solves a surprising share of mysteries:
- Did you save? Pocket Studio usually saves as you type, but check.
- Is the reported line the line you were editing? If not, look at what you edited anyway.
- Count the brackets on the line above the reported one.
Expecting '}'almost never means the problem is where it says. - Read the message out loud.
Argument type mismatch: actual type is 'Int', but 'String' was expectedis completely plain English once spoken. - Undo back to the last version that worked. Then redo one change at a time. This is unglamorous and it works every single time.
Notice that "ask an AI" is not on that list. It is a legitimate tool and you will use it eventually. But an assistant that answers before you have read the message trains you out of the exact skill this lesson exists to build.
Break your app on purpose, three times. Nothing is at stake, and you will recognise all three for the rest of your life.
- Open Hello Pocket → MainActivity.kt.
- Break the grammar. Delete the closing
}on the very last line of the file. Tap Run. Read what appears. Note that the reported line number is nowhere near the deletion. Put the brace back. - Break a name. Change
Text(toTxet(. Tap Run. Find thee:line in the log and read the file, line and column from it. Now scroll to the bottom and look at theFAILURE:block — confirm for yourself that it tells you nothing useful. Fix the name. - Break an import. Scroll to the top and delete the line
import androidx.compose.material3.Text. Tap Run. You getUnresolved reference 'Text'even thoughTextis spelled correctly — because nothing told this file whereTextlives. Put the import back, or tap the red underline and accept the suggested import. - Fix everything and build once more to confirm you are back to a working app.
- Optional: with the app running, open Logcat and watch the messages scroll while you rotate the phone. None of them are errors. That is what a healthy app looks like.
compileDebugKotlin is the step that compiles your Kotlin, so the real message is a line beginning e: printed earlier in the log.e:. That line names the file, line and column. Fix that one thing and build again.w: never stops a build; only e: does..kt: number. Go to that line and check the number you used to look something up.Caused by:.Caused by: in the block — that is the true origin. Then find the first line under it naming your own file.Text comes from. The import line for it is missing or was deleted.import androidx.compose.material3.Text near the top with the other imports — or tap the red underline in the editor and accept the import it offers.- Errors are the normal working conditions of programming, not a verdict on you.
- Three kinds: a red underline while typing, a when you press Run, and a once the app is running.
- A Kotlin error line is
e: file:line:column message. The column number is the fastest way to the exact word. - Gradle's
FAILURE:block names the failed task, not your mistake. The real message is further up the log. - In a , find the topmost line with your own package name. In a chain, the last
Caused by:is the true origin. - Fix the first error, change one thing, then rebuild.
- Next: the least technical lesson in the course, and possibly the most useful — how to keep going for the next fifteen hours without burning out.