当显示对话框时执行 animateTo 时,Android 的地图库会抛出 NullPointerException
我已经在 runOnFirstFix() 方法上苦苦挣扎了很长一段时间。也许问题出在第一行,上面写着Running deferred on first fix
。
问题是,当执行第一个修复并且我在那一刻显示一些对话框时,它经常崩溃。
我从 logcat 中提取了以下内容:
I/Maps.MyLocationOverlay( 2425): Running deferred on first fix: com.MyApp.Map$2@43aef8e8
W/dalvikvm( 2425): threadid=23: thread exiting with uncaught exception (group=0x4001e170)
E/AndroidRuntime( 2425): Uncaught handler: thread Thread-24 exiting due to uncaught exception
E/AndroidRuntime( 2425): java.lang.NullPointerException
E/AndroidRuntime( 2425): at com.google.android.maps.MapController.animateTo(MapController.java:232)
E/AndroidRuntime( 2425): at com.google.android.maps.MapController.animateTo(MapController.java:203)
E/AndroidRuntime( 2425): at com.MyApp.Map$2.run(Map.java:129)
E/AndroidRuntime( 2425): at java.lang.Thread.run(Thread.java:1096)
我没有找到任何类似的参考内容,这让我怀疑我在非常基本的层面上做错了什么。有人见过这个吗?
I've been struggling with the runOnFirstFix() method for quite a long time. And maybe the problem is in that first line that says Running deferred on first fix
.
The thing is, when the first fix gets executed and I am displaying some dialog in that moment, it crashes quite frequently.
I've extracted the following from the logcat:
I/Maps.MyLocationOverlay( 2425): Running deferred on first fix: com.MyApp.Map$2@43aef8e8
W/dalvikvm( 2425): threadid=23: thread exiting with uncaught exception (group=0x4001e170)
E/AndroidRuntime( 2425): Uncaught handler: thread Thread-24 exiting due to uncaught exception
E/AndroidRuntime( 2425): java.lang.NullPointerException
E/AndroidRuntime( 2425): at com.google.android.maps.MapController.animateTo(MapController.java:232)
E/AndroidRuntime( 2425): at com.google.android.maps.MapController.animateTo(MapController.java:203)
E/AndroidRuntime( 2425): at com.MyApp.Map$2.run(Map.java:129)
E/AndroidRuntime( 2425): at java.lang.Thread.run(Thread.java:1096)
I haven't found any reference to anything similar and that makes me suspect I am doing something wrong in a very basic level. Has anyone seen this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我基本上有一个带有 MapView 的 MapActivity,并在其上添加了 MyLocationOverlay
然后,在执行过程中的某个时刻,该活动通过 showDialog(...) 显示一个对话框,并且,如果在“animateTo”方法执行时该对话框仍然显示调用,它崩溃了。
I basically have a MapActivity with a MapView and I add a MyLocationOverlay on it
Then, at some point in the execution the activity shows a dialog via showDialog(...) and, if the dialog is still showing when the 'animateTo' method is called, it crashes.
正如我在 run() 方法中看到的那样,这可能是您不在 UI 线程上调用 animateTo 的问题。我认为你应该将其发布到 UI 线程上以使其正常工作
As I see this in a run()-method it could be the problem that you call animateTo not on the UI thread. I think you should post that on the UI thread to make it working