Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 382
Fustigador Avatar asked Oct 27 '15 12:10

Fustigador


1 Answers

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

like image 150
vaibhav Avatar answered Sep 19 '22 07:09

vaibhav