GraphHopper.com | Forum | GitHub | Maps | Blog

Directions-api-client-hc: java.lang.NoSuchMethodError: okio.BufferedSource.rangeEquals(JLokio/ByteString;)Z


#1

Hi,

I have encountered a problem related to the okio dependency while using the directions-api-client-hc to send and consume a MatrixRequest to the Directions API.

This is the code in order to reproduce:

GraphHopperMatrixWeb matrixClient = new GraphHopperMatrixWeb();
matrixClient.setKey(API_KEY);

GHMRequest request = new GHMRequest();
request.addFromPoints(Arrays.asList(new GHPoint(48.844055, 2.311129), new GHPoint(48.836792, 2.351729), new GHPoint(48.884376, 2.366178)));
request.addToPoints(Arrays.asList(new GHPoint(48.896827, 2.325425), new GHPoint(48.893765, 2.212104)));
request.addOutArray("distances");
request.addOutArray("times");
request.setVehicle("car");

MatrixResponse response = matrixClient.route(request);

This is the exception I’m having:

Exception in thread "main" java.lang.NoSuchMethodError: okio.BufferedSource.rangeEquals(JLokio/ByteString;)Z
	at okhttp3.internal.Util.bomAwareCharset(Util.java:431)
	at okhttp3.ResponseBody.string(ResponseBody.java:174)
	at com.graphhopper.api.GHMatrixAbstractRequester.postJson(GHMatrixAbstractRequester.java:73)
	at com.graphhopper.api.GHMatrixBatchRequester.route(GHMatrixBatchRequester.java:97)
	at com.graphhopper.api.GraphHopperMatrixWeb.route(GraphHopperMatrixWeb.java:44)
	at com.praxedo.executables.forecast.ghdirectionsapi.DirectionsApi.main(DirectionsApi.java:25)

I have cleaned my local dependencies but I am still having the same problem. I’m not sure if it is related to my local environment or if it is a problem on the dependencies of the directions-api-client-hc. Can anyone confirm it ?

Thank you,
José


#2

When using a fresh project (via IntelliJ) and the code below it works without the mentioned exception. I used the following maven snippet:

<dependency>
    <groupId>com.graphhopper</groupId>
    <artifactId>directions-api-client-hc</artifactId>
    <version>0.10.0</version>
</dependency>

Do you have multiple different versions of okhttp3 in the classpath? This dependency uses 3.8.0


#3

It turns out I had an older okhttp dependency brought by another dependecy. Nothing is wrong with the GraphHopper client, everything works fine. Sorry about that.