Retrofit 2.0 beta 4 response get IllegalArgumentException

浪尽此生 提交于 2019-12-10 22:19:21

问题


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?


回答1:


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>() {

...

});


来源:https://stackoverflow.com/questions/35602521/retrofit-2-0-beta-4-response-get-illegalargumentexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!