touchingtwist touchingtwist - 7 months ago 43
Android Question

How to check response code on Android retrofit?


Call<ResponseBody> call = postApiService.uploadFile(body, coordinatePoint, textToPost);
call.enqueue(new Callback<ResponseBody>() {
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Toast.makeText(getContext(), response.code(), Toast.LENGTH_LONG).show();
else {
Toast.makeText(getContext(), response.code(), Toast.LENGTH_LONG).show();
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(getContext(), getString(R.string.check_internet), Toast.LENGTH_LONG).show();

On this code, i think error is on

Because error code is like
android.content.res.Resources$NotFoundException: String resource ID #0xc9

on that
Toast.makeText(getContext(), response.code(), Toast.LENGTH_LONG).show();

So, how to get response code on android retrofit2?

Please would you let me know about it?


You are getting the android.content.res.Resources$NotFoundException: String resource ID #0xc9 message because you are calling makeText(Context context, int resId, int duration) in onResponse. Here, the second parameter expects a string resource ID of type int, but you are passing a response code instead. Simply convert your response code to a String to print out the correct value:

Toast.makeText(getContext(), Integer.toString(response.code()), Toast.LENGTH_LONG).show();