Most Android crashes end with a generic Unfortunately, app has stopped toast. Behind that message is a stack trace that tells you exactly which class or method threw an exception. Without that information you are guessing, which leads to wasted time and repeated reinstall‑and‑hope cycles. This guide shows you how to capture the stack trace reliably, interpret it, and apply a fix – all without rooting the device.
Build number seven times). Then enable USB debugging (Settings ▶ System ▶ Developer options ▶ USB debugging).adb) and, optionally, Android Studio if you want a graphical view of the logs.com.example.myapp). You can find it in Play Store URL or by running adb shell pm list packages | grep myapp.adb devices
You should see a line with the device serial number and the word device.com.example.myapp with your app’s package:
adb logcat --pid=$(adb shell pidof -s com.example.myapp) *:E
If the app is not running yet, you can start it and then run the command, or use a broader filter:
adb logcat | grep "com.example.myapp"FATAL EXCEPTION.Ctrl+C to stop logcat and redirect the output to a file for later analysis:
adb logcat -d > crash_log.txtcrash_log.txt in any text editor and search for FATAL EXCEPTION. The lines immediately following show the exception type, message, and the call stack.
FATAL EXCEPTION: main
Process: com.example.myapp, PID: 12345
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at com.example.myapp.ui.MainActivity.onCreate(MainActivity.java:45)
...The stack trace is a reverse chronological list of method calls that led to the exception. The topmost line (after the exception type) points to the exact line in your source code that caused the crash. If you have the source, open that file and line number to see the offending code.
NullPointerException, IllegalStateException) tells you what went wrong.Welcome screen). You don’t need the app’s source code to view logs.Errorcom.example.myappFATAL EXCEPTION block.Copy, and paste into a text file for annotation.NullPointerException – a variable wasn’t initialized.ArrayIndexOutOfBoundsException – accessing an array with an invalid index.NetworkOnMainThreadException – performing network I/O on the UI thread.?. (Kotlin) or if (obj != null) (Java)?if (userName != null) {
int length = userName.length();
}AsyncTask, Executor, or Kotlin coroutines.adb install -r app.apk) and repeat the steps that previously caused the crash. Verify that the exception no longer appears in logcat.Log.e() before the risky line to capture variable states in future crashes.
Log.e("MyApp", "userName=" + userName);
FATAL EXCEPTION.so) and only prints a SIGSEGV without Java stack.-b all flag to capture all buffers, then look for signal 11 (SIGSEGV). Use ndk-stack with the appropriate symbols file if you have native source.
Stay awake in Developer options (Settings ▶ Developer options ▶ Stay awake). Keep the screen on while reproducing.adb logcat without filters.
--pid filter shown earlier, or create a custom filter:
adb logcat -s com.example.myapp:D *:SIf your release APK is built with ProGuard or R8, the stack trace will contain short class names like a.b.c. To translate them back, locate the mapping.txt generated during the build (usually in app/build/outputs/mapping/release/) and run:
java -jar retrace.jar mapping.txt crash_log.txt
The output will show the original class and method names, letting you pinpoint the source of the crash even in an obfuscated build.
adb logcat with a PID or package filter.FATAL EXCEPTION block.mapping.txt.If after applying the fix the crash persists, or the stack trace points to a third‑party library you cannot modify, consider these steps:
Stack Overflow or the library’s issue tracker.With the systematic approach above you’ll move from “my app keeps crashing” to “I know exactly why and how to fix it”, saving hours of blind testing.









