Need recommendation for good resource on troubleshooting android using logcat and the console [duplicate]
everyone. Can anyone recommend a good resource that gives insight on how to troubleshoot android using the LogCat and the Console? Any help would be much appreciated :)
I never saw anything written, but here are a few tips (or, at least, this is how I do it):
Tracing the error in the stack:
- When you're troubleshooting after a force close, then always look for the
ERROR
part of the logcat. It will be followed by the exception type. - If you get a not-that-useful
java.lang.RuntimeException
, search below for the original exception thrown, e.g.Caused by: java.lang.NullPointerException
- These exceptions will be followed by the stack trace of your app. You can find in there where the exception was thrown (class, method and line) and which methods called it. Try to find your package in there and figure out how it got to that exception.
- If it is an exception you don't know about, google it: I usually use "java 6 xxx.xxx.xxException" or "android xxx.xxx.xxException" to quickly get the link to the API documentation about that exception.
- Then read the docs about the class that is throwing the exception (e.g., which are the cases it can be null, etc.)
- When you're troubleshooting after a force close, then always look for the
Customizing the logs
- I abuse of the
Log.d("MyClass", "Some variable =" + variable);
. It ends up to be very informative. Some times I just use the log to check where in anif
/else
tree am I or to trace constructors (useful to know if I am reusing an object, or creating a new one some times). - If the logcat is too noisy, I use grep and a particular marker for my logs, e.g.,
Log.d("***> MyClass", "Some variable =" + variable);
orLog.d("***> MyClass2", "onCreate()");
, I filter those using a simpleadb logcat | grep '\*\*\*>'
- You can quickly filter for errors in the log using
adb logcat *:E
- I abuse of the
- When everything else fails: Post the trace here :)
精彩评论