views:

72

answers:

1

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?

A: 

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.

martin