Every developer spends a significant portion of their career debugging code. When your application crashes or Gradle fails to build, understanding how to read Logcat stack traces and diagnose build logs separates amateur programmers from seasoned engineers.
Cause: Attempting to invoke a method on an object reference that is null.
Fix: Migrate code to Kotlin non-nullable types, use safe calls object?.method(), and provide fallbacks via the Elvis operator ?:.
Cause: Calling startActivity(intent) where the Activity is not declared in the manifest.
Fix: Add <activity android:name=".MyActivity" android:exported="false" /> inside AndroidManifest.xml.
Cause: Performing an HTTP request or socket read directly on the main UI thread.
Fix: Wrap network calls in Kotlin Coroutines with withContext(Dispatchers.IO) {}.
Cause: App heap memory exhausted, usually from decoding full-resolution camera bitmaps.
Fix: Use Coil or Glide for automatic downsampling, and use LeakCanary to detect leaked Activity contexts.
Cause: Calling sensitive APIs (Camera, Location) without asking for runtime permission.
Fix: Declare permission in AndroidManifest.xml AND request at runtime via ActivityResultContracts.RequestPermission().
Cause: Project requires Java 17/21, but Android Studio is pointing to an older Java 8/11 JDK.
Fix: In Android Studio, go to Settings > Build, Execution, Deployment > Build Tools > Gradle and set Gradle JDK to embedded JDK 17 or 21.
Logcat displays system messages and custom debug logs. Use Logcat query syntax to isolate crashes instantly:
package:mine level:error — Filters logs to display only uncaught exceptions from your own app package.tag:MyTag — Filters output to logs emitted by Log.d("MyTag", "...").is:crash — Isolates the fatal crash stack trace showing the exact class and line number of the failure.Broaden your foundational and advanced Android application development skills across our curriculum:
Deep dive into memory leaks, CPU profiling, and heap dumps.
Prepare answers for common debugging scenarios in interviews.
Explain crash diagnostics and Logcat commands in viva exams.
Quick commands for ADB, Logcat filters, and Gradle flags.