Hello Google Maps Example NULL Pointer Exception

醉酒当歌 提交于 2020-01-15 18:50:33

问题


I am creating a google maps application for android and I am following the guide at http://developer.android.com/resources/tutorials/views/hello-mapview.html to get started.

I can run the app just fine in my emulator, but when I click on the overlay item I get a NULL Pointer Exception. The trace is below. I'm new to Android and have no idea how to debug this. So any help would be greatly appreciated.

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)

Thanks!


回答1:


That rings a bell. I think the solution can be found here: http://www.anddev.org/map-problems-f26/error-when-trying-to-access-overlay-text-t12324.html?sid=87163bc814ce6ded7400844529c7d7f3#wrap




回答2:


generally speaking, try to catch exceptions and make use of Log and TAG. http://developer.android.com/reference/android/util/Log.html. This helped me a lot!

A basic tutorial: http://www.androidza.co.za/beyond-hello-world-logcat-and-exception-handling/




回答3:


Maybe you use the one-param constructor like I did,But theAlertDialog.Builder need a instantiated object,which you may forget to do.



来源:https://stackoverflow.com/questions/8572409/hello-google-maps-example-null-pointer-exception

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