I am trying to use the GraphHopper core and JSON APIs(0.10.0 for both) to create a graph using GeoJSON and then do a routing. However I run into a couple of exceptions. Here is the relevant part of my code:
gh = new GraphHopper().forMobile(); ... other code (omitted) ... // This code runs in a background thread GHJsonFactory fac = new GHJsonFactory(); GHJson json = fac.create(); Reader reader = new FileReader(Environment.getExternalStorageDirectory().getAbsolutePath() + "/data.json"); JsonFeatureCollection features = json.fromJson(reader, JsonFeatureCollection.class); gh.changeGraph(features.getFeatures()); GHRequest request = new GHRequest(51.05, -0.72, 51.0291, -0.7621). setAlgorithm(Parameters.Algorithms.DIJKSTRA_BI).setVehicle("foot"); GHResponse resp = gh.route(request); PathWrapper pw = resp.getBest();
Initially I got this error:
IllegalArgumentException: To use the changeGraph API you need to turn off CH
I then added, immediately before changeGraph():
but now get:
NullPointerException: Attempt to invoke virtual method 'java.util.List com.graphhopper.routing.util.EncodingManager.fetchEdgeEncoders() on a null object reference
Looks like I’ve missed a step somewhere. The above code was based on my own examination of the GraphHopper source code. Any suggestions on this?