简体   繁体   中英

Cannot resolve method handleResponse using observable

I have a function loadProfile()

private void loadProfile() {
        mSubscriptions.add(RetrofitClient.getRetrofit(mToken).getProfile(mEmail)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(this::handleResponse,this::handleError));
}

which calls handleResponse

private void handleResponse(Response response, User user) {
     //some code
}

And handleResponse is defined in my Api class like this:

@GET("Users/{id}")
Observable<retrofit2.Response<User>> getProfile(@Path("id") String id);

And I am getting cannot resolve method handleResponse in loadProfile() I checked parameter types as many similar questions suggest, but can't find the problem. I hope I provided everything necessary to find the problem.

Since your return type is Observable<Response<User>>

I think your method should be

    private void handleResponse(Response<User> response) {
        if (response.isSuccessful()) {
            User user = response.body()
        } else {
            // some code
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM