Eclipse logcat debugging

风流意气都作罢 提交于 2019-11-26 08:38:10

问题


I have a beginner question, I want to debug my app and i don\'t know how to use the Logcat properly.

Right now, I am getting this error and i don\'t know what it means.

How can i use this information? Is there a tutorial somewhere i can watch?

Thanks for your help.

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.

回答1:


After you see

FATAL EXCEPTION: main

you will see the problem, here a NPE

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

then you find the first line that references your app. Here it is the following line

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

This says that in Start.java something is null in onClick() at line 49. So you go to that line and see what could be null...like a variable that tries to access a method such as setText(), getText(), or any Android or user defined method. Sometimes it is simple why it is null and sometimes you have to trace back further to see what makes it null.

Edit

If a variable is null it is because it hasn't been initialized properly, or at all. So maybe you have a variable TextView tv; but you never gave it a value by doing something like

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

if you try to do something like tv.setText("Some Text"); you will get a NPE because you didn't initialize it with something like the above line of code. Or maybe you tried to initialize it and used the wrong id like one from a different layout. This will return null and create a NPE in the same way. This can be on any variable that you try to call a method on.




回答2:


It says it's NullPointerException at 49 th line on Start.java file.

Logcat allows you to filter you your all logs from left pan. Which is the best thing over there.




回答3:


you can try this tips to use 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"); 

}

See result on logcat, then you can see your step..



来源:https://stackoverflow.com/questions/18964329/eclipse-logcat-debugging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!