moe
moe

Reputation: 167

How to interpret Logcat

Can anyone tell me how I should read the errors in Logcat? I'd like to understand where my problem is.

At the moment, I tried to read it but can't find the cause of the crash.

Here's the Logcat I don't understand:

05-18 18:29:44.160: ERROR/AndroidRuntime(2145): FATAL EXCEPTION: main
05-18 18:29:44.160: ERROR/AndroidRuntime(2145): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.paad.whereami/com.paad.whereami.WhereAmI}: java.lang.NullPointerException
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.os.Looper.loop(Looper.java:130)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread.main(ActivityThread.java:3683)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at java.lang.reflect.Method.invokeNative(Native Method)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at java.lang.reflect.Method.invoke(Method.java:507)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at dalvik.system.NativeStart.main(Native Method)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145): Caused by: java.lang.NullPointerException
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at com.paad.whereami.WhereAmI.updateWithNewLocation(WhereAmI.java:290)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at com.paad.whereami.WhereAmI.onCreate(WhereAmI.java:216)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

Upvotes: 16

Views: 17018

Answers (2)

guipivoto
guipivoto

Reputation: 18677

DOCS

Basic tool from Android to collect/analyse logs is the logcat.

HERE is the Android's page about logcat

If you use android Studio, you can also check this LINK.

Capturing

Basically, you can MANUALLY capture logcat with following command (or just check AndroidMonitor window in AndroidStudio):

adb logcat

There's a lot of parameters you can add to command which helps you to filter and display the message that you want... This is personal... I always use the command below to get the message timestamp:

adb logcat -v time

You can redirect the output to a file and analyze it in a Text Editor.

Analyzing

Your app is crashing and you are getting an error like this:

05-18 18:29:44.160: ERROR/AndroidRuntime(2145): FATAL EXCEPTION: main
05-18 18:29:44.160: ERROR/AndroidRuntime(2145): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.paad.whereami/com.paad.whereami.WhereAmI}: java.lang.NullPointerException
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.os.Looper.loop(Looper.java:130)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread.main(ActivityThread.java:3683)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at java.lang.reflect.Method.invokeNative(Native Method)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at java.lang.reflect.Method.invoke(Method.java:507)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at dalvik.system.NativeStart.main(Native Method)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145): Caused by: java.lang.NullPointerException
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at com.paad.whereami.WhereAmI.updateWithNewLocation(WhereAmI.java:290)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at com.paad.whereami.WhereAmI.onCreate(WhereAmI.java:216)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-18 18:29:44.160: ERROR/AndroidRuntime(2145):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

This part of the log shows you a lot of information:

When

When the issue happened: 05-18 18:29:44.160

It is important to check when the issue happened... You may find several errors in a log... you must be sure that you are checking the proper messages :)

Which App

App which crashed: com.paad.whereami

This way, you know which app crashed (to be sure that you are checking the logs about your message)

Which Error

ERROR: java.lang.NullPointerException

A NULL Pointer Exception error

Which file is leading to this error

Usually, we read only the first line of the stack trace. However, your log is a good example that we need to check whole log. In the lines below, we can see were the null pointer happened:

Caused by: java.lang.NullPointerException
    at com.paad.whereami.WhereAmI.updateWithNewLocation(WhereAmI.java:290)
    at com.paad.whereami.WhereAmI.onCreate(WhereAmI.java:216)

Error happened in file WhereAmI.java, inside updateWithNewLocation() method at line: 290 (stacktrace shows the line that error happened)

StackTrace

You can see which method called updateWithNewLocation(). This is usefull because sometimes, the error was produced in calling methods. In you example, it was called:

at com.paad.whereami.WhereAmI.onCreate(WhereAmI.java:216)

etc....

Overview

This was just an overview... Not all logs are simple etc... It is just to share the idea and provide a entry-level information to you...

I hope I could help you someway... Regards

Upvotes: 5

FoamyGuy
FoamyGuy

Reputation: 46846

The second "part" of your log is going to be what is important for you in this instance.

Caused by: java.lang.NullPointerException

This means that somewhere in your code something is set to null and you are trying to use it as though it isn't.

The next few lines tell you where in your code you can find the error.

at com.paad.whereami.WhereAmI.updateWithNewLocation(WhereAmI.java:290)
at com.paad.whereami.WhereAmI.onCreate(WhereAmI.java:216)

This should mean that you have a method named updateWithNewLocation that you are calling from onCreate at line 216. The error is coming from inside this method at line 290. Take a look at line 290 in your code. Whatever you are trying to do on that line is causing the exception because something is null that shouldn't be.

Upvotes: 31

Related Questions