当显示对话框时执行 animateTo 时,Android 的地图库会抛出 NullPointerException

发布于 2024-09-18 19:54:20 字数 912 浏览 9 评论 0原文

我已经在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的那么颓废 2024-09-25 19:54:21

我基本上有一个带有 MapView 的 MapActivity,并在其上添加了 MyLocationOverlay

//My location overlay
myLocation = new MyLocationOverlay(this, mapView);
myLocation.enableMyLocation();
mapView.getOverlays().add(myLocation);      
myLocation.runOnFirstFix(new Runnable(){


 @Override
   public void run() {
    MapController myController = Map.this.mapView.getController();
                  myController.animateTo(application.myLocation.getMyLocation());
   }
    });

然后,在执行过程中的某个时刻,该活动通过 showDialog(...) 显示一个对话框,并且,如果在“animateTo”方法执行时该对话框仍然显示调用,它崩溃了。

I basically have a MapActivity with a MapView and I add a MyLocationOverlay on it

//My location overlay
myLocation = new MyLocationOverlay(this, mapView);
myLocation.enableMyLocation();
mapView.getOverlays().add(myLocation);      
myLocation.runOnFirstFix(new Runnable(){


 @Override
   public void run() {
    MapController myController = Map.this.mapView.getController();
                  myController.animateTo(application.myLocation.getMyLocation());
   }
    });

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.

不可一世的女人 2024-09-25 19:54:21

正如我在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文