Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a better error message when multiple callback types are in use. #827

Closed
IgorGanapolsky opened this issue Apr 30, 2015 · 8 comments
Closed

Comments

@IgorGanapolsky
Copy link

Hello,
I am using retrofit 1.9.0, and getting a strange error:

Error: retrofit.RetrofitError:: No Retrofit annotation found. (parameter #2)

I defined my api method like this:
@POST("/login") Observable<Customer> doEmailLogin(@Body LoginBody loginBody, Callback<ResponseBody> callback);

What could be causing this error with my Callback interface??

Thank you,
Igor

@JakeWharton
Copy link
Member

Both returning the observable and the callback are mechanisms of how the request is executed. You don't need both, only one.

In this case, Retrofit sees the observable as the way the request will be executed and treats all of the method parameters as part of how the request will be created. Since the callback parameter has no annotation, it thinks this is an error. Simply remove the callback or change the return type to void.

I'll leave this issue open as a reminder to create a better error message for this case.

@IgorGanapolsky
Copy link
Author

But according to your logic, there is no way for me to parse the ResponseBody. AFAIK, I need a custom Callback for that. Am I wrong?

@JakeWharton
Copy link
Member

Callback is a mechanism of notifying you of data just as the observable is. There is no way to receive both the ResponseBody and a Customer instance. They both represent the same thing in different forms.

@IgorGanapolsky
Copy link
Author

Oh wait, I just had to do:
.subscribe(new Subscriber<Response>() {

@IgorGanapolsky
Copy link
Author

@JakeWharton Thanks for the tip. Have some @changetip bitcoin $1 on me.

@changetip
Copy link

Hi @JakeWharton, @IgorGanapolsky sent you a Bitcoin tip worth 4,251 bits ($1.00), and I'm here to deliver it ➔ collect your tip.

Learn more about ChangeTip

@JakeWharton JakeWharton changed the title No Retrofit annotation found. (parameter #2) Use a better error message when multiple callback types are in use. May 12, 2015
@JakeWharton
Copy link
Member

This was fixed as a side-effect of the massive #845 change. The v2.0 release will have better messaging around erroneous usage of the execution mechanism.

@dinhthaidaica
Copy link

Could you tell me how it was resolve in v 2.0 ?
I have same problem and still get stuck, can not call '.subscribe(new Subscriber() {' any more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants