开发者

Need recommendation for good resource on troubleshooting android using logcat and the console [duplicate]

This question already has answers here: 开发者_如何学运维 Unfortunately MyApp has stopped. How can I solve this? (23 answers) Closed 1 year ago.

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.)
  • 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 an if/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); or Log.d("***> MyClass2", "onCreate()");, I filter those using a simple adb logcat | grep '\*\*\*>'
    • You can quickly filter for errors in the log using adb logcat *:E
  • When everything else fails: Post the trace here :)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜