剛開始從事Android時,未免會碰到一些對高手來說是簡單的問題,但卻會讓新手無所解決辦法的問題,我也是一個新手, 這裡將保存一些我從事Android開發的一些技術備忘,期望對後續的新來者有益。
1,通過LogCat窗口發現一下錯誤提示信息:01-30 12:13:15.829: I/System.out(3043): waiting for debugger to settle...
01-30 12:13:16.039: I/System.out(3043): debugger has settled (1342)
01-30 12:13:21.570: D/AndroidRuntime(3043): Shutting down VM
01-30 12:13:21.570: W/dalvikvm(3043): threadid=1: thread exiting with uncaught exception (group=0x40018578)
01-30 12:13:21.640: E/AndroidRuntime(3043): FATAL EXCEPTION: main
01-30 12:13:21.640: E/AndroidRuntime(3043): java.lang.RuntimeException: Unable to start activity ComponentInfo{loger.gps.any2go.com/loger.gps.any2go.com.GpsActivity}: java.lang.NullPointerException
01-30 12:13:21.640: E/AndroidRuntime(3043): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
01-30 12:13:21.640: E/AndroidRuntime(3043): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-30 12:13:21.640: E/AndroidRuntime(3043): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-30 12:13:21.640: E/AndroidRuntime(3043): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-30 12:13:21.640: E/AndroidRuntime(3043): at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 12:13:21.640: E/AndroidRuntime(3043): at android.os.Looper.loop(Looper.java:130)
01-30 12:13:21.640: E/AndroidRuntime(3043): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-30 12:13:21.640: E/AndroidRuntime(3043): at java.lang.reflect.Method.invokeNative(Native Method)
01-30 12:13:21.640: E/AndroidRuntime(3043): at java.lang.reflect.Method.invoke(Method.java:507)
01-30 12:13:21.640: E/AndroidRuntime(3043): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-30 12:13:21.640: E/AndroidRuntime(3043): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-30 12:13:21.640: E/AndroidRuntime(3043): at dalvik.system.NativeStart.main(Native Method)
01-30 12:13:21.640: E/AndroidRuntime(3043): Caused by: java.lang.NullPointerException
01-30 12:13:21.640: E/AndroidRuntime(3043): at loger.gps.any2go.com.GpsActivity.onCreate(GpsActivity.java:31)
01-30 12:13:21.640: E/AndroidRuntime(3043): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-30 12:13:21.640: E/AndroidRuntime(3043): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
01-30 12:13:21.640: E/AndroidRuntime(3043): ... 11 more
通過以上信息可以看出, LogCat已經幫我們定位了具體的問題所在,如第一行寒色所示,出現的是Main函數中出現一樣, 而異常是NullPointerException,具體的發生在綠色背景的行,OnCreate函數中。 GPSActive.java:31 行。
這樣我們就具體地發現了問題所在, 這個問題迷惑了我一個下午,而現在我重新看看,幾分鐘就發現了, 發表於此,以資共勉。