FARID FARID -4 years ago 83
Android Question

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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download