gpt4 book ai didi

java - Eclipse logcat 调试

转载 作者:行者123 更新时间:2023-11-29 05:37:26 33 4
gpt4 key购买 nike

我有一个新手问题,我想调试我的应用程序,但我不知道如何正确使用 Logcat。

现在,我收到此错误,但我不知道它是什么意思。

我如何使用这些信息?有没有我可以看的教程?

感谢您的帮助。

09-23 11:27:55.968: E/AndroidRuntime(807): FATAL EXCEPTION: main
09-23 11:27:55.968: E/AndroidRuntime(807): java.lang.NullPointerException
09-23 11:27:55.968: E/AndroidRuntime(807): at com.uniqueapps.runner.Start.onClick(Start.java:49)
09-23 11:27:55.968: E/AndroidRuntime(807): at android.view.View.performClick(View.java:4240)
09-23 11:27:55.968: E/AndroidRuntime(807): at android.view.View$PerformClick.run(View.java:17721)
09-23 11:27:55.968: E/AndroidRuntime(807): at android.os.Handler.handleCallback(Handler.java:730)
09-23 11:27:55.968: E/AndroidRuntime(807): at android.os.Handler.dispatchMessage(Handler.java:92)
09-23 11:27:55.968: E/AndroidRuntime(807): at android.os.Looper.loop(Looper.java:137)
09-23 11:27:55.968: E/AndroidRuntime(807): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-23 11:27:55.968: E/AndroidRuntime(807): at java.lang.reflect.Method.invokeNative(Native Method)
09-23 11:27:55.968: E/AndroidRuntime(807): at java.lang.reflect.Method.invoke(Method.java:525)
09-23 11:27:55.968: E/AndroidRuntime(807): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-23 11:27:55.968: E/AndroidRuntime(807): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-23 11:27:55.968: E/AndroidRuntime(807): at dalvik.system.NativeStart.main(Native Method)
09-23 11:27:59.528: I/Process(807): Sending signal. PID: 807 SIG: 9
09-23 11:28:01.108: D/gralloc_goldfish(877): Emulator without GPU emulation detected.
09-23 11:54:55.318: D/gralloc_goldfish(937): Emulator without GPU emulation detected.
09-23 11:54:57.887: I/Choreographer(937): Skipped 35 frames! The application may be doing too much work on its main thread.
09-23 11:55:03.118: D/dalvikvm(937): GC_FOR_ALLOC freed 89K, 7% free 2928K/3136K, paused 39ms, total 72ms
09-23 11:55:05.858: D/AndroidRuntime(937): Shutting down VM
09-23 11:55:05.858: W/dalvikvm(937): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
09-23 11:55:05.868: E/AndroidRuntime(937): FATAL EXCEPTION: main
09-23 11:55:05.868: E/AndroidRuntime(937): java.lang.NullPointerException
09-23 11:55:05.868: E/AndroidRuntime(937): at com.uniqueapps.runner.Start.onClick(Start.java:49)
09-23 11:55:05.868: E/AndroidRuntime(937): at android.view.View.performClick(View.java:4240)
09-23 11:55:05.868: E/AndroidRuntime(937): at android.view.View$PerformClick.run(View.java:17721)
09-23 11:55:05.868: E/AndroidRuntime(937): at android.os.Handler.handleCallback(Handler.java:730)
09-23 11:55:05.868: E/AndroidRuntime(937): at android.os.Handler.dispatchMessage(Handler.java:92)
09-23 11:55:05.868: E/AndroidRuntime(937): at android.os.Looper.loop(Looper.java:137)
09-23 11:55:05.868: E/AndroidRuntime(937): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-23 11:55:05.868: E/AndroidRuntime(937): at java.lang.reflect.Method.invokeNative(Native Method)
09-23 11:55:05.868: E/AndroidRuntime(937): at java.lang.reflect.Method.invoke(Method.java:525)
09-23 11:55:05.868: E/AndroidRuntime(937): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-23 11:55:05.868: E/AndroidRuntime(937): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-23 11:55:05.868: E/AndroidRuntime(937): at dalvik.system.NativeStart.main(Native Method)
09-23 11:55:09.657: D/gralloc_goldfish(961): Emulator without GPU emulation detected.
09-23 12:04:20.418: D/gralloc_goldfish(1006): Emulator without GPU emulation detected.
09-23 12:04:27.118: D/dalvikvm(1006): GC_FOR_ALLOC freed 96K, 7% free 2919K/3136K, paused 40ms, total 72ms
09-23 12:04:30.337: D/AndroidRuntime(1006): Shutting down VM
09-23 12:04:30.357: W/dalvikvm(1006): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
09-23 12:04:30.397: E/AndroidRuntime(1006): FATAL EXCEPTION: main
09-23 12:04:30.397: E/AndroidRuntime(1006): java.lang.NullPointerException
09-23 12:04:30.397: E/AndroidRuntime(1006): at com.uniqueapps.runner.Start.onClick(Start.java:49)
09-23 12:04:30.397: E/AndroidRuntime(1006): at android.view.View.performClick(View.java:4240)
09-23 12:04:30.397: E/AndroidRuntime(1006): at android.view.View$PerformClick.run(View.java:17721)
09-23 12:04:30.397: E/AndroidRuntime(1006): at android.os.Handler.handleCallback(Handler.java:730)
09-23 12:04:30.397: E/AndroidRuntime(1006): at android.os.Handler.dispatchMessage(Handler.java:92)
09-23 12:04:30.397: E/AndroidRuntime(1006): at android.os.Looper.loop(Looper.java:137)
09-23 12:04:30.397: E/AndroidRuntime(1006): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-23 12:04:30.397: E/AndroidRuntime(1006): at java.lang.reflect.Method.invokeNative(Native Method)
09-23 12:04:30.397: E/AndroidRuntime(1006): at java.lang.reflect.Method.invoke(Method.java:525)
09-23 12:04:30.397: E/AndroidRuntime(1006): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-23 12:04:30.397: E/AndroidRuntime(1006): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-23 12:04:30.397: E/AndroidRuntime(1006): at dalvik.system.NativeStart.main(Native Method)
09-23 12:04:33.918: D/gralloc_goldfish(1030): Emulator without GPU emulation detected.

最佳答案

看完之后

FATAL EXCEPTION: main

你会看到问题,这里是一个NPE

09-23 11:27:55.968: E/AndroidRuntime(807): java.lang.NullPointerException

然后您会找到引用您的应用的第一行。这是下面一行

at com.uniqueapps.runner.Start.onClick(Start.java:49)

这表示在 Start.java 中第 49 行的 onClick() 中有些东西是 null。所以你去那一行看看什么可能null...就像一个试图访问方法的变量,例如setText()getText(),或任何 Android 或用户定义的方法。有时它是 null 的原因很简单,有时您必须进一步追溯以查看是什么让它成为 null

编辑

如果变量为 null,那是因为它没有正确初始化,或者根本没有初始化。所以也许你有一个变量 TextView tv; 但你从来没有通过像

这样的事情给它赋值
 tv = (TextView) findViewById(R.id.myTV);

如果您尝试执行类似 tv.setText("Some Text"); 的操作,您将得到一个 NPE,因为您没有使用类似以上代码行。或者您尝试初始化它并使用了错误的 id,就像来自不同 layout 的一样。这将返回 null 并以相同的方式创建一个 NPE。这可以在您尝试对其调用方法的任何变量上。

关于java - Eclipse logcat 调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18964329/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com