java.lang.IllegalArgumentException:找不到Retrofit注释。 (参数#2)

时间:2017-07-08 03:28:00

标签: android retrofit retrofit2

我遇到错误:java.lang.IllegalArgumentException:找不到Retrofit注释。 (参数#2)

我需要进行的POST调用具有以下内容的主体结构:

"auth": {
    "email": "<EMAIL>",
    "password": "<PASSWORD>"
}

我似乎无法找到我做错的事情......想法?

    AppService api = ApiUtils.getService();
    api.login(new LoginRequest(emailEditText.getText().toString(), passwordEditText.getText().toString()), new Callback<Response>() {
        @Override
        public void onResponse(Call<Response> call, Response<Response> response) {
        }

        @Override
        public void onFailure(Call<Response> call, Throwable t) {
        }
    });


public class ApiUtils {
    public static final String BASE_URL = "https://<API-URL>/";

    public static AppService getService() {
        return RetrofitClient.getClient(BASE_URL).create(AppService.class);
    }
}

public interface AppService {
    @POST("/<ENDPOINT>")
    Call<Void> login(
        @Body LoginRequest request,
        Callback<Response> callback
    );
}


public class LoginRequest {
    @Expose
    CreateLogin auth;

    private class CreateLogin {
        @Expose private String email;
        @Expose private String password;
    }

    public LoginRequest(String email, String password) {
        auth = new CreateLogin();
        auth.email = email;
        auth.password = password;
    }
}

public class RetrofitClient {

    private static Retrofit retrofit = null;

    public static Retrofit getClient(String baseUrl) {
        if (retrofit==null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .addConverterFactory(GsonConverterFactory.create())
                     .build();
        }
        return retrofit;
   }
}

0 个答案:

没有答案