Farid
Farid

Reputation: 2553

Retrofit server callback throws error

I have implemented retrofit in my application. All server request and responses working properly. However when I execute the following line:

response = getRestClient().osrmGetRoute(mAppRouteRequest).execute();

It throws following exception:

Attempt to invoke virtual method 'java.lang.String okhttp3.ResponseBody.string()' on a null object reference

Well, app gets a proper JSON response from server and I'm using Gson (de)serializer.

Upvotes: 0

Views: 448

Answers (1)

CDVN
CDVN

Reputation: 171

Make sure that you check the message body before using it. If you are getting status code 200 then the response contains a message.

Upvotes: 2

Related Questions