如何解读Logcat

发布于 2024-11-08 12:54:42 字数 2348 浏览 0 评论 0原文

谁能告诉我如何读取 Logcat 中的错误?我想了解我的问题出在哪里。

目前,我尝试阅读它,但找不到崩溃的原因。

这是我不明白的 Logcat:

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿咻 2024-11-15 12:54:42

在这种情况下,日志的第二“部分”对您来说很重要。

原因:
java.lang.NullPointerException

这意味着代码中的某处被设置为 null 并且您试图使用它,就好像它不是一样。

接下来的几行告诉您可以在代码中的何处找到错误。

位于 com.paad.whereami.WhereAmI.updateWithNewLocation(WhereAmI.java:290)
在 com.paad.whereami.WhereAmI.onCreate(WhereAmI.java:216)

这应该意味着您有一个名为 updateWithNewLocation 的方法,您正在从 onCreate 调用该方法 在第 216 行。错误来自该方法内部的第 290 行。查看代码中的第 290 行。无论您尝试在该行上执行什么操作都会导致异常,因为某些不应该为 null 的内容。

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.

百合的盛世恋 2024-11-15 12:54:42

DOCS

Android 中用于收集/分析日志的基本工具是 logcat。

这里是Android关于logcat的页面

如果你使用android Studio,你可以另请检查此链接

捕获

基本上,您可以使用以下命令手动捕获 logcat(或者仅检查 AndroidStudio 中的 AndroidMonitor 窗口):

adb logcat

您可以在命令中添加很多参数,以帮助您过滤和显示您想要的消息...这是个人的...我总是使用下面的命令来获取消息时间戳:

adb logcat -v time

您可以将输出重定向到文件并在文本编辑器中分析它。

分析

您的应用崩溃了,并且收到如下错误:

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)

日志的这一部分向您显示了大量信息:

时间

问题发生的时间:05 -18 18:29:44.160

检查问题何时发生非常重要...您可能会在日志中发现多个错误...您必须确保检查正确的消息:)

哪个应用

程序崩溃了:com.paad.whereami

这样,您就知道哪个应用程序崩溃了(以确保您正在检查有关消息的日志)

哪个错误< /strong>

错误:java.lang.NullPointerException

空指针异常错误

哪个文件导致此错误

通常,我们只读取堆栈跟踪的第一行。但是,您的日志是一个很好的例子,我们需要检查整个日志。在下面的行中,我们可以看到是否发生了空指针:

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

错误发生在文件 WhereAmI.java 中,位于 updateWithNewLocation() 方法内,位于第:290行code> (stacktrace 显示发生错误的行)

StackTrace

您可以看到哪个方法调用了 updateWithNewLocation()。这很有用,因为有时错误是在调用方法时产生的。在您的示例中,它被称为:

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

等等...

概述

这只是一个概述...并非所有日志都很简单等等...这只是为了分享想法并提供一个条目-向您提供级别信息...

我希望我能以某种方式帮助您...
问候

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文