Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

java - Eclipse logcat debugging

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...