Ahmed Mohammed
Ahmed Mohammed

Reputation: 337

Retrofit 2.0 beta 4 response get IllegalArgumentException

I am using retrofit 1.9 and i created logout method as

@GET("/user/logout")
void logoutUser(Callback<Response> callback);

logoutUser(new RequestCallback<Response>(this) {
    @Override
    public void success(Response response, Response response2) {
        settingsService.setUserLoggedOut();
        getMainActivity().finish();
    }
});

i upgraded it to retrofit 2.0 beta 4 and used this code

@GET("user/logout")
Call<Response> logoutUser();

logoutUser().enqueue(new RequestCallback<Response>(this) {
    @Override
    public void onResponse(Call<Response> call, Response<Response> response) {
        settingsService.setUserLoggedOut();
        getMainActivity().finish();
    }
});

I have this exception : java.lang.IllegalArgumentException: 'retrofit2.Response' is not a valid response body type. Did you mean ResponseBody?

what is the problem?

Upvotes: 2

Views: 1668

Answers (1)

shivgadhia
shivgadhia

Reputation: 66

I was able to overcome this by this answer: https://stackoverflow.com/a/33228322

So try:

@GET("user/logout")
Call<ResponseBody> logoutUser();

Where ResponseBody is an okhttp3.ResponseBody

and then

logoutUser().enqueue(new Callback<ResponseBody>() {

...

});

Upvotes: 5

Related Questions