Yuriy Kolbasinskiy
Yuriy Kolbasinskiy

Reputation: 3841

Get response from server with retrofit

I'd like to get Response from server using retforit. Here is some code:

public class ApiManager {
private static String API_URL = "http://192.168.0.142:8080";
private static ApiService service;

interface ApiService {

    @GET("/login")
    Call<User> auth(Callback<User> cb);
}

private ApiManager() {
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(API_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    service = retrofit.create(ApiService.class);
}

public void login(String login, String password) {
    service.auth(new Callback<User>() {
                     @Override
                     public void onResponse(retrofit.Response<User> response) {

                     }

                     @Override
                     public void onFailure(Throwable t) {

                     }
                 }

    );

And User class:

public class User {
private String token;

public String getToken() {
    return token;
}

public void setToken(String token) {
    this.token = token;
}

}

Server return JSONObject {"token": "verysecrettoken"} anyway.

When i call login method app was crashed with Exception java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1)

What's wrong? Where i can find retrofit documentation? What is it Call? Please help

Upvotes: 3

Views: 1491

Answers (2)

guillaume_fr
guillaume_fr

Reputation: 501

Call enqueue, you have the wrong syntax. Try with this early doc:

http://inthecheesefactory.com/blog/retrofit-2.0/en

Upvotes: 1

lgvalle
lgvalle

Reputation: 3762

Same question is asked here: No Retrofit annotation found. (parameter #1)

Retrofit documentation can be found here: http://square.github.io/retrofit/

Upvotes: 0

Related Questions