我正在为Android创建一个谷歌地图应用程序,我正在按照http://developer.android.com/resources/tutorials/views/hello-mapview.html的指南开始。
我可以在我的模拟器中运行应用程序,但是当我点击覆盖项时,我得到一个NULL指针异常。跟踪如下。我是Android新手,不知道如何调试它。所以任何帮助都将不胜感激。
12-20 02:57:05.898: W/dalvikvm(473): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-20 02:57:05.928: E/AndroidRuntime(473): FATAL EXCEPTION: main
12-20 02:57:05.928: E/AndroidRuntime(473): java.lang.NullPointerException
12-20 02:57:05.928: E/AndroidRuntime(473): at com.android.internal.app.AlertController$AlertParams.<init>(AlertController.java:742)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.app.AlertDialog$Builder.<init>(AlertDialog.java:273)
12-20 02:57:05.928: E/AndroidRuntime(473): at hello.google.maps.HelloItemizedOverlay.onTap(HelloItemizedOverlay.java:41)
12-20 02:57:05.928: E/AndroidRuntime(473): at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
12-20 02:57:05.928: E/AndroidRuntime(473): at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
12-20 02:57:05.928: E/AndroidRuntime(473): at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:356)
12-20 02:57:05.928: E/AndroidRuntime(473): at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533)
12-20 02:57:05.928: E/AndroidRuntime(473): at com.google.android.maps.MapView.onTouchEvent(MapView.java:683)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.view.View.dispatchTouchEvent(View.java:3885)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
12-20 02:57:05.928: E/AndroidRuntime(473): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
12-20 02:57:05.928: E/AndroidRuntime(473): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
12-20 02:57:05.928: E/AndroidRuntime(473): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.os.Looper.loop(Looper.java:130)
12-20 02:57:05.928: E/AndroidRuntime(473): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-20 02:57:05.928: E/AndroidRuntime(473): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 02:57:05.928: E/AndroidRuntime(473): at java.lang.reflect.Method.invoke(Method.java:507)
12-20 02:57:05.928: E/AndroidRuntime(473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-20 02:57:05.928: E/AndroidRuntime(473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-20 02:57:05.928: E/AndroidRuntime(473): at dalvik.system.NativeStart.main(Native Method)
谢谢!
答案 0 :(得分:3)
敲响了钟声。我认为解决方案可以在这里找到:http://www.anddev.org/map-problems-f26/error-when-trying-to-access-overlay-text-t12324.html?sid=87163bc814ce6ded7400844529c7d7f3#wrap
答案 1 :(得分:0)
一般来说,尝试捕获异常并使用Log
和TAG
。
http://developer.android.com/reference/android/util/Log.html。
这对我帮助很大!
基础教程:http://www.androidza.co.za/beyond-hello-world-logcat-and-exception-handling/
答案 2 :(得分:0)
也许你像我一样使用one-param构造函数,但是AlertDialog.Builder
需要一个实例化的对象,你可能会忘记这样做。