Find your first bug with the debugger
Use breakpoints, variable inspection, and Logcat to understand app behavior.
What you’ll learn
Before you start
- A running debug build in Android Studio
1. Run a debug build
Open your activity in Android Studio and place a breakpoint inside a click listener. Start a debug session on a connected device or emulator, then tap the button.
2. Inspect program state
When execution pauses, inspect variables and the call stack. Step over a statement to see how state changes. Avoid evaluating expressions with side effects while diagnosing a problem.
3. Read a crash
Filter Logcat for your process. Find the exception type and follow the stack trace to the first frame in your own code. The line at that frame is the starting point, though the underlying mistake may have occurred earlier.
Log.d("CounterActivity", "Counter updated to " + count);Import android.util.Log. Never log access tokens, passwords, or personal data.
Expected output
The breakpoint pauses the app before executing the selected statement. Continuing resumes normal interaction. A debug message appears in Logcat when that line runs.
Troubleshooting
If a breakpoint is not hit, verify the process, build variant, and code path. A release build may optimize or omit code; use a debuggable variant for this exercise.