Debugging is the process of understanding why the app behaves differently from what you expected. Good debugging is calm, systematic, and evidence-based.
Start With The Error
If the app crashes, open Logcat and find the exception.
Common crash types:
| Error | Meaning |
|---|---|
NullPointerException | You used a missing value |
IndexOutOfBoundsException | You accessed a bad list index |
IllegalStateException | An API was used in the wrong state |
SecurityException | Missing permission or restricted access |
Read the first useful line that points to your app code.
Logcat
Add logs when you need runtime visibility.
Log.d("LoginViewModel", "Submit clicked with email=$email")
Do not leave noisy logs everywhere. Use them to investigate, then clean them up or make them meaningful.
Breakpoints
A breakpoint pauses the app at a line of code. Use Debug instead of Run, click next to a line number, and inspect variables when execution stops.
Breakpoints are great for:
- checking function inputs
- following branch decisions
- inspecting API responses
- verifying state updates
Step Through Code
Use:
- Step Over: run current line
- Step Into: enter a function
- Step Out: finish current function
- Resume: continue app execution
Layout Inspector
When a composable looks wrong — wrong size, unexpected clipping, invisible overlap — use the Layout Inspector.
Go to View → Tool Windows → Layout Inspector while the app is running. It shows a live view of the composable tree, lets you click any element, and shows the applied modifiers and their values.
This is much faster than guessing at padding and size values.
Debugging Compose State
For Compose bugs, ask:
- Is the state actually changing?
- Is the composable reading the right state?
- Is state duplicated in two places?
- Is a list mutated instead of replaced?
Practice
Create a counter app with a deliberate bug: clicking the button does not increase the number. Use logs and breakpoints to find why.
Summary
Debugging is a core engineering skill. Learn Logcat, stack traces, breakpoints, stepping, and state inspection. The faster you can find truth, the faster you can build.