When an app suddenly closes or behaves erratically, the first place to look is the crash log. Android records a detailed stack trace for every unhandled exception, and you can retrieve it with the adb tool and logcat without needing root access. This tutorial walks you through the entire workflow: preparing the device, capturing the log, filtering the relevant lines, and interpreting the output to pinpoint the cause.
adb over Wi‑Fi after the initial USB setup.Why this matters: USB debugging exposes a secure channel that lets adb communicate with the device. Without it, the computer cannot issue logcat commands.
C:\adb on Windows or ~/adb on macOS/Linux).PATH so you can run adb from any terminal.
export PATH=$PATH:~/adb to your ~/.bashrc or ~/.zshrc.adb version
You should see something like Android Debug Bridge version 1.0.41.Tip: If your computer asks to install a driver (Windows), let it do so. The generic Google USB driver works for most devices.
adb devices
device.
0123456789ABCDEF device
If you see unauthorized, check the phone for the debugging permission dialog and grant access.
There are two common scenarios: you know which app crashes, or you want to capture any crash that happens while the device is idle.
adb shell pm list packages | grep -i partial_name
logcat filtered to that package and write to a file:
adb logcat --pid=$(adb shell pidof -s com.example.app) -v threadtime > crash_log.txt
Explanation: pidof -s returns the process ID of the app; -v threadtime adds timestamps and thread IDs for easier reading.
FATAL EXCEPTION:
adb logcat *:S AndroidRuntime:E > full_crash.txt
Explanation: *:S silences all tags, while AndroidRuntime:E keeps only error‑level messages from the runtime, which include stack traces.
full_crash.txt now contains the full stack trace.Logcat files can be large. Use simple command‑line tools to isolate the exact stack trace.
E/AndroidRuntime or contain FATAL EXCEPTION.findstr (Windows):
grep -A 20 "FATAL EXCEPTION" crash_log.txt > filtered.txt
This extracts the crash line and the next 20 lines (usually the full stack).
Now you have a concise file (filtered.txt) that you can share with developers or keep for personal reference.
Understanding the stack trace is the key to fixing the problem. Here’s a typical Android crash snippet:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.app, PID: 12345
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at com.example.app.ui.MainActivity.onCreate(MainActivity.java:45)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1300)
... 9 more
Break it down:
NullPointerException tells you a null reference was accessed.com.example.app.ui.MainActivity.onCreate(MainActivity.java:45) points to the exact file and line number.main indicates the UI thread; crashes on background threads may have different implications.If you have the app’s source code (open‑source apps, your own project), open the indicated file and line. If you don’t have source, you can still infer the problematic area by searching the package name on the Play Store or GitHub.
| Pattern | Typical Cause | Quick Fix |
|---|---|---|
java.lang.IllegalStateException: Fragment ... not attached to a context | Attempting UI work after the fragment is detached. | Check isAdded() before UI calls or move work to onViewCreated(). |
java.lang.OutOfMemoryError | Loading large bitmaps without recycling. | Use BitmapFactory.Options.inSampleSize or Glide/Picasso with proper caching. |
android.content.ActivityNotFoundException | Calling startActivity() with an intent that no app can handle. | Validate with resolveActivity() before launching. |
adb devices again; if it shows unauthorized, confirm the dialog on the phone.-G option to increase the buffer size (requires root on older devices, but on many newer devices you can set it without root):
adb logcat -G 16M
sudo only if necessary).Suppose you downloaded a free weather app that crashes on launch. Follow the steps:
adb devices).adb logcat *:S AndroidRuntime:E > weather_crash.txt
weather_crash.txt and locate the stack trace. You find:
java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.example.weather.WeatherInfo.city' on a null object reference
at com.example.weather.ui.MainActivity.updateUI(MainActivity.java:78)
MainActivity.java at line 78 shows the app assumes the network response is non‑null.
city. After the fix, the app launches correctly.
This example demonstrates how a concise logcat capture can save hours of guesswork.
zip filtered.txt) to keep the attachment size small.adb logcat -b crash to read the dedicated crash buffer that Android maintains for recent fatal crashes.#!/bin/bash
adb logcat -b crash -d > $(date +%Y%m%d_%H%M%S)_crash.txt
Running the script after a crash gives you a timestamped file automatically.
With these steps you can reliably capture, filter, and interpret Android crash logs without rooting. Whether you’re a hobbyist developer, a power user troubleshooting a misbehaving app, or a support technician, the workflow outlined here gives you the data you need to diagnose the problem and communicate it effectively.









