Mobile Map Package mmpk File Loads Sometimes But Not Always

02-15-2020 08:38 PM
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(
at com.esri.arcgisruntime.internal.loadable.LoadableImpl.getLoadStatus(
at com.esri.arcgisruntime.mapping.MobileMapPackage.getLoadStatus(
at TurnByTurn.lambda$setupMobileMap$1(
at java.base/ Method)
at Method)
at java.base/

When it loads the outputs are:

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

Any help with this would be greatly appreciated.

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.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();

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" );
} 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
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.


0 Kudos