Fustigador
Fustigador

Reputation: 6459

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

I have this Interface:

public interface InterfazAguaHttp {

@FormUrlEncoded
@POST("/")
Call<String> saveContador(@Field("contador") Long contador, Callback<String> callBack);
}

The rest of the code is this:

Retrofit builder = new Retrofit.Builder()
                            .baseUrl(ValoresGlobales.urlServlet)
                            .addConverterFactory(GsonConverterFactory.create())
                            .build();
                    InterfazAguaHttp interfaz = builder.create(InterfazAguaHttp.class);
                        Call<String> respuesta = interfaz.saveContador(93847597L, new Callback<String>() {
                            @Override
                            public void onResponse(Response<String> response, Retrofit retrofit) {
                                //Some logging
                            }

                            @Override
                            public void onFailure(Throwable t) {
                                //Some logging
                            }
                        });

This is all inside a try-catch block. In the catch, I am receiving this error:

Error: No Retrofit annotation found. (parameter #2) for method InterfazAguaHttp.saveContador

How could I get rid of this error, and still have my callback?

Thank you.

Upvotes: 5

Views: 19212

Answers (1)

vaibhav
vaibhav

Reputation: 816

change your interface method to this

public interface InterfazAguaHttp {

@FormUrlEncoded
@POST("/")
Call<String> saveContador(@Field("contador") Long contador);
}

and the rest of the code like this

Retrofit builder = new Retrofit.Builder()
                            .baseUrl(ValoresGlobales.urlServlet)
                            .addConverterFactory(GsonConverterFactory.create())
                            .build();
                    InterfazAguaHttp interfaz = builder.create(InterfazAguaHttp.class);
                        Call<String> respuesta = interfaz.saveContador(93847597L);
                        respuesta.enqueue(new Callback<String>() {
                            @Override
                            public void onResponse(Response<String> response, Retrofit retrofit) {
                                //Some logging
                            }

                            @Override
                            public void onFailure(Throwable t) {
                                //Some logging
                            }
                        });

Link for reference

Upvotes: 17

Related Questions