1

I am currently trying to use MapsForge to display a map in an Activity in my application. Everything works well, I can display the map an add a Polyline to it using a route provided by GraphHopper.

As I was advised by the 'Getting Started' section of MapsForge, I set up the following code. You can close the Activity with a button in it OR with the hardawre 'return' button.

Code of my button's listener:

buttonRetour.setOnClickListener(new Button.OnClickListener() {  

   public void onClick(View v) {
         finish();
   }
});

Code of my methods:

@Override
    protected void onStop() {
        mapView.getLayerManager().getLayers().remove(tileRendererLayer);
        tileRendererLayer.onDestroy();
        super.onStop();
    }

@Override
    protected void onDestroy() {
        tileCache.destroy();
        super.onDestroy();
    }

And the Variables;

public class RunActivity extends Activity {
    private MapView mapView;
    private TileCache tileCache;
    private TileRendererLayer tileRendererLayer;

But when I close the Activity with buttonRetour, I get the following error:

06-08 10:30:25.051: E/AndroidRuntime(8895): FATAL EXCEPTION: main
06-08 10:30:25.051: E/AndroidRuntime(8895): java.lang.RuntimeException: Unable to stop activity {icam.Travelr.Core/icam.Travelr.Core.RunActivity}: java.lang.NullPointerException
06-08 10:30:25.051: E/AndroidRuntime(8895):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3072)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3126)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at android.app.ActivityThread.access$1200(ActivityThread.java:122)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1179)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at android.os.Looper.loop(Looper.java:137)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at android.app.ActivityThread.main(ActivityThread.java:4340)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at java.lang.reflect.Method.invokeNative(Native Method)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at java.lang.reflect.Method.invoke(Method.java:511)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at dalvik.system.NativeStart.main(Native Method)
06-08 10:30:25.051: E/AndroidRuntime(8895): Caused by: java.lang.NullPointerException
06-08 10:30:25.051: E/AndroidRuntime(8895):     at icam.Travelr.Core.RunActivity.onStop(RunActivity.java:372)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1174)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at android.app.Activity.performStop(Activity.java:4603)
06-08 10:30:25.051: E/AndroidRuntime(8895):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3067)
06-08 10:30:25.051: E/AndroidRuntime(8895):     ... 11 more

I've tried to put

mapView.getLayerManager().getLayers().remove(tileRendererLayer);
tileRendererLayer.onDestroy();
tileCache.destroy();

just before the finish() call and it worked, but I obviously can't use it; if I close my Activity using the hardware return button, I'll trigger an OutOfMemory error sooner or later (I've tried). I've also tried to put all the calls in the onStop() function, and after the super(). Nothing worked. None of the calls works on itself, every single one triggers an error when the others are commented.

I'm working with MapsForge 0.4.3 on Android 4.0 (14)

Does anybody have an idea of what could trigger this, and how I can resolve this? That seemed to have been an issue solved since the version 0.3 .

4

0 回答 0