1

我有一个初学者问题,我想调试我的应用程序,但我不知道如何正确使用 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.
4

3 回答 3

3

你看到后

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)

这表示在第 49 行中存在Start.java某些内容。因此,您转到该行并查看可能是什么......就像一个变量,它试图访问诸如 , 或任何 Android 或用户定义的方法之类的方法。有时它的原因很简单,有时您必须进一步追溯以了解它的原因。nullonClick()nullsetText()getText()nullnull

编辑

如果是一个变量,null那是因为它没有被正确初始化,或者根本没有被初始化。所以也许你有一个变量TextView tv;,但你从来没有通过做类似的事情给它一个值

 tv = (TextView) findViewById(R.id.myTV);

如果您尝试做类似的事情,tv.setText("Some Text");您将得到 aNPE因为您没有使用上述代码行之类的东西对其进行初始化。或者,也许您尝试初始化它并使用了错误,id例如来自不同的layout. 这将以相同的方式返回null并创建一个NPE。这可以在您尝试调用方法的任何变量上。

于 2013-09-23T16:40:17.170 回答
0

它在 Start.java 文件的第 49 行说它是 NullPointerException。

Logcat 允许您从左侧面板中过滤所有日志。这是那里最好的东西。

于 2013-09-23T16:34:06.840 回答
0

你可以试试这个技巧来使用 logcat ..

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    System.out.println("1. Before Declare");

    textView = (TextView) findViewById(R.id.textView);

    System.out.println("2. After Declare"); 

}

在 logcat 上查看结果,然后您可以看到您的步骤..

于 2013-09-23T17:56:32.233 回答