Mobile Map Package mmpk File Loads Sometimes But Not Always

509
1
02-15-2020 08:38 PM
AlyssaAbram
New Contributor

I'm having an issue with loading an mmpk ( i think). Some times it will load, sometimes it will fail, and sometimes it will hang. I haven't been able to figure out what is causing this as I can run the project a few times in a row and get different results, without changing any code between runs. I am very new to the java SDK and I'm trying to teach myself with the tutorials. I combined two tutorials, find route and get a route and directions offline, into one project to try to get turn by turn directions from an mmpk file. Both tutorials work fine on their own. Here's most of my code. When it actually loads, it mostly works (I'm still working on getting the find and reset buttons to work for point and click start and end points) I have notated what line is indicated by the error message.

When it fails/hangs the outputs I have included are:

Start Function
SetupMobileMap Function
Exit SetupMobileMap Function
SetupGraphicsOverlay Function
exit start

The error message is:

Exception in thread "JavaFX Application Thread" com.esri.arcgisruntime.ArcGISRuntimeException: Invalid argument: Null value.
at com.esri.arcgisruntime.internal.jni.CoreMobileMapPackage.nativeGetLoadStatus(Native Method)
at com.esri.arcgisruntime.internal.jni.CoreMobileMapPackage.getLoadStatus(CoreMobileMapPackage.java:142)
at com.esri.arcgisruntime.internal.loadable.LoadableImpl.getLoadStatus(LoadableImpl.java:125)
at com.esri.arcgisruntime.mapping.MobileMapPackage.getLoadStatus(MobileMapPackage.java:326)
at TurnByTurn.lambda$setupMobileMap$1(TurnByTurn.java:134)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)

When it loads the outputs are:

Start Function
SetupMobileMap Function
Exit SetupMobileMap Function
SetupGraphicsOverlay Function
exit start
LOADED
2
Calling setupRouteTask
SetupRouteTask Function
Licensed For Developer Use Only
CreateRouteAndDisplay Function
SolveForRoute Function

Any help with this would be greatly appreciated.

@Override
public void start ( Stage stage )
{
    System.out.println( "Start Function" );

    stackPane = new StackPane(  );
    Scene scene = new Scene( stackPane );

    stage.setTitle( "Navigation" );
    stage.setWidth( 800 );
    stage.setHeight( 700 );
    stage.show();
    stage.setScene( scene );


    controlsVBox = new VBox(6);
    controlsVBox.setBackground( new Background( new BackgroundFill( Paint.valueOf( "rgba(0,0,0,0.3)" ),
            CornerRadii.EMPTY, Insets.EMPTY ) ) );
    controlsVBox.setPadding( new Insets( 10.0 ) );
    controlsVBox.setMaxSize( 400,300 );
    controlsVBox.getStyleClass().add( "panel-region" );

    Label directionsLabel = new Label("Route directions");
    directionsLabel.getStyleClass().add( "panel-label" );

    findButton = new Button("Find Route");
    findButton.setMaxWidth( Double.MAX_VALUE  );
    findButton.setDisable( true );

    resetButton = new Button("Reset");
    resetButton.setMaxWidth( Double.MAX_VALUE );
    resetButton.setDisable( true );


    controlsVBox.getChildren().addAll( directionsLabel, directionsList, findButton, resetButton );
    mapView = new MapView();
    setupMobileMap();
    setupGraphicsOverlay();

    System.out.println( "exit start" );
}

public void setupGraphicsOverlay()
{
    System.out.println( "SetupGraphicsOverlay Function" );

    if(mapView != null)
    {
        routeGraphicsOverlay = new GraphicsOverlay(  );
        mapView.getGraphicsOverlays().add( routeGraphicsOverlay );

    }
}

public void setupMobileMap()
{
    System.out.println( "SetupMobileMap Function" );

    if(mapView != null)
    {
        String mmpkFile = "Greater_Los_Angeles.mmpk";
        final MobileMapPackage mapPackage = new MobileMapPackage( mmpkFile );
        mapPackage.loadAsync(); //this was below the listener but tired it here based on the SDK documentation (no change)
        mapPackage.addDoneLoadingListener( () -> {
            //it fails on the line below. I added the two output statements for debugging, so when those are
            //removed it fails on the if statement.
            System.out.println( mapPackage.getLoadStatus() );   //<---
            System.out.println( mapPackage.getMaps().size() );
            if(mapPackage.getLoadStatus() == LoadStatus.LOADED && mapPackage.getMaps().size() > 0)
            {
                double latitude = 34.05293;
                double longitude = -118.24368;
                double scale = 220000;

                ArcGISMap map = mapPackage.getMaps().get(0);
                transportationNetwork = map.getTransportationNetworks().get( 0 );
                mapView.setMap( map );
                map.setInitialViewpoint( new Viewpoint( latitude,longitude,scale ) );
                stackPane.getChildren().addAll(mapView, controlsVBox);
                StackPane.setAlignment(controlsVBox, Pos.TOP_LEFT);
                StackPane.setMargin(controlsVBox, new Insets(10, 0, 0, 10));

                    mapView.addDrawStatusChangedListener( g ->
                    {
                        if(g.getDrawStatus() == DrawStatus.COMPLETED)
                        {
                            findButton.setDisable( false );
                        }
                    });
                System.out.println( "Calling setupRouteTask" );
                setupRouteTask();
            } else
            {
                new Alert( Alert.AlertType.ERROR, "MMPK failed to load: "
                        + mapPackage.getLoadError().getMessage() ).show();
            }
        } );

    } else
    {
        System.out.println( "MapView was Null" );
    }
    System.out.println( "Exit SetupMobileMap Function" );
}
0 Kudos
1 Reply
AlanLucas
Esri Contributor

Hi Alyssa,

I'm not sure but I wonder if the mapPackage object might be garbage-collected before the done-loading listener is called, because it goes out of scope when setupMobileMap returns. Try making it a member field to ensure it's not garbage-collected.

Alan

0 Kudos