刚开始从事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 行。
这样我们就具体地发现了问题所在, 这个问题迷惑了我一个下午,而现在我重新看看,几分钟就发现了, 发表于此,以资共勉。