Hi Ramesh,
I've had a play with this code and I suspect what is happening is the RouteTask is failing to load so you are going ahead and reading the default parameters on a service which isn't working. You need to perform some more checks in your code. I would also apply the same checks in your iOS app as it would fail in the same way.
My Kotlin skills are not perfect so I've tried to explain this in Java code, but the concept will be the same.
I have connected to the route service using the following code. This is for demo purposes only and I'd recommend using Oauth instead for obvious reasons:
UserCredential userCredential = new UserCredential("username","password");
RouteTask routeTask = new RouteTask("http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World");
routeTask.setCredential(userCredential);
You should then load the route task and listen into the done loading listener:
routeTask.loadAsync();
routeTask.addDoneLoadingListener(()-> {
At this point in the code you have either loaded the service or something might have gone wrong! You need to check the load status.
if (routeTask.getLoadStatus() == LoadStatus.LOADED) {
try {
RouteParameters routeParameters = routeTask.createDefaultParametersAsync().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
} else {
// failed to load so lets report the error
System.out.println("error " + routeTask.getLoadError().getCause());
}
});
So you can see above that if you have got a successful connection the service you can read the default parameters. If not the error will display on the console.
If you directly run the code above which obviously has a poor user credential you will see:
-- loaded FAILED_TO_LOAD
-- error com.esri.arcgisruntime.io.JsonEmbeddedException: Unable to generate token.
If you leave the user credential out you might see
-- error com.esri.arcgisruntime.io.JsonEmbeddedException: Token Required
The iOS SDK for runtime uses the same pattern for checking the loading of services. This will help to explain it:
Loadable pattern for asynchronous resources—ArcGIS Runtime SDK for Android | ArcGIS for Developers