AnsweredAssumed Answered

Input Spatial Reference is null when attempting to route

Question asked by davidgalindo on Feb 13, 2019

I'm working with React Native and ArcGIS 100.4 for Android. While I was able to get routing working on the iOS side, it looks like Android is having issues. Here is the relevant code:

public RNAGSRouter(Context context) {
    routeTask = new RouteTask(context, routeUrl);
    routeTask.loadAsync();
    routeParameters = new RouteParameters();
    routeTask.addDoneLoadingListener(() -> {
        ListenableFuture<RouteParameters> future = routeTask.createDefaultParametersAsync();
        future.addDoneListener(() -> {
            try {
                RouteParameters result = future.get();
                routeParameters.setTravelMode(result.getTravelMode());
                routeParameters.setOutputSpatialReference(SpatialReferences.getWgs84());
            } catch (Exception e) {
                Log.w("WARNING (AGS)", "Routing parameters failed to load. Perhaps the app has not received valid credentials?");
                e.printStackTrace();
            }
        });
    });
}

public Route createRoute(@NonNull GraphicsOverlay graphicsOverlay, @Nullable ArrayList<String> excludeGraphics){
    // Clear stops
    routeParameters.clearStops();
    // I know this is deprecated but it just works ._. setStops does not work... good job, Esri
    // See https://developers.arcgis.com/android/latest/api-reference/reference/com/esri/arcgisruntime/tasks/networkanalysis/RouteParameters.html
    List<Stop> stops = routeParameters.getStops();
    for (Graphic item: graphicsOverlay.getGraphics()) {
        String referenceId = ((String) item.getAttributes().get("referenceId"));
        if (excludeGraphics == null || !(excludeGraphics.contains(referenceId))) {
            // Reform the point with spatial reference
            Point point = ((Point) item.getGeometry());
            stops.add(new Stop(point));
        }
    }
    routeParameters.setOutputSpatialReference(SpatialReferences.getWgs84());
    ListenableFuture<RouteResult> future  = routeTask.solveRouteAsync(routeParameters);
    try {
        RouteResult result = future.get();
        if (result == null || result.getRoutes().isEmpty()) {
            return null;
        }
        return result.getRoutes().get(0);
    } catch(Exception e) {
        e.printStackTrace();
        return null;
    }
}

I hope that is legible, as it's a pain to reformat. Upon running the future.get() call, the app jumps to the catch with an ArcGISRuntimeException, stating "invalid argument" and "Input spatial reference must not be null." I'm pretty sure this is a low level issue, but I'm not sure if there's anything else I can do differently. Any ideas? 

 

Here's the stack trace:

2019-02-13 16:27:40.959 28547-28547/com.samplearcgis W/System.err: java.util.concurrent.ExecutionException: com.esri.arcgisruntime.ArcGISRuntimeException: Invalid argument
2019-02-13 16:27:40.960 28547-28547/com.samplearcgis W/System.err: at com.esri.arcgisruntime.internal.b.b.get(SourceFile:130)
2019-02-13 16:27:40.960 28547-28547/com.samplearcgis W/System.err: at com.samplearcgis.RNAGSRouter.createRoute(RNAGSRouter.java:74)
2019-02-13 16:27:40.961 28547-28547/com.samplearcgis W/System.err: at com.samplearcgis.RNAGSMapView.routeGraphicsOverlay(RNAGSMapView.java:289)
2019-02-13 16:27:40.962 28547-28547/com.samplearcgis W/System.err: at com.samplearcgis.RNArcGISMapViewManager.receiveCommand(RNArcGISMapViewManager.java:86)
2019-02-13 16:27:40.962 28547-28547/com.samplearcgis W/System.err: at com.samplearcgis.RNArcGISMapViewManager.receiveCommand(RNArcGISMapViewManager.java:14)
2019-02-13 16:27:40.962 28547-28547/com.samplearcgis W/System.err: at com.facebook.react.uimanager.NativeViewHierarchyManager.dispatchCommand(NativeViewHierarchyManager.java:760)
2019-02-13 16:27:40.963 28547-28547/com.samplearcgis W/System.err: at com.facebook.react.uimanager.UIViewOperationQueue$DispatchCommandOperation.execute(UIViewOperationQueue.java:309)
2019-02-13 16:27:40.965 28547-28547/com.samplearcgis W/System.err: at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:917)
2019-02-13 16:27:40.965 28547-28547/com.samplearcgis W/System.err: at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:1025)
2019-02-13 16:27:40.966 28547-28547/com.samplearcgis W/System.err: at com.facebook.react.uimanager.UIViewOperationQueue.access$2600(UIViewOperationQueue.java:46)
2019-02-13 16:27:40.966 28547-28547/com.samplearcgis W/System.err: at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1085)
2019-02-13 16:27:40.967 28547-28547/com.samplearcgis W/System.err: at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
2019-02-13 16:27:40.967 28547-28547/com.samplearcgis W/System.err: at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:166)
2019-02-13 16:27:40.967 28547-28547/com.samplearcgis W/System.err: at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:110)
2019-02-13 16:27:40.968 28547-28547/com.samplearcgis W/System.err: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:872)
2019-02-13 16:27:40.968 28547-28547/com.samplearcgis W/System.err: at android.view.Choreographer.doCallbacks(Choreographer.java:686)
2019-02-13 16:27:40.968 28547-28547/com.samplearcgis W/System.err: at android.view.Choreographer.doFrame(Choreographer.java:618)
2019-02-13 16:27:40.968 28547-28547/com.samplearcgis W/System.err: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
2019-02-13 16:27:40.968 28547-28547/com.samplearcgis W/System.err: at android.os.Handler.handleCallback(Handler.java:751)
2019-02-13 16:27:40.968 28547-28547/com.samplearcgis W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
2019-02-13 16:27:40.969 28547-28547/com.samplearcgis W/System.err: at android.os.Looper.loop(Looper.java:154)
2019-02-13 16:27:40.969 28547-28547/com.samplearcgis W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6119)
2019-02-13 16:27:40.969 28547-28547/com.samplearcgis W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2019-02-13 16:27:40.969 28547-28547/com.samplearcgis W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
2019-02-13 16:27:40.969 28547-28547/com.samplearcgis W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
2019-02-13 16:27:40.969 28547-28547/com.samplearcgis W/System.err: Caused by: com.esri.arcgisruntime.ArcGISRuntimeException: Invalid argument
2019-02-13 16:27:40.970 28547-28547/com.samplearcgis W/System.err: at com.esri.arcgisruntime.internal.b.b.get(SourceFile:122)
2019-02-13 16:27:40.970 28547-28547/com.samplearcgis W/System.err: ... 24 more

Outcomes