【问题标题】:Error: No Retrofit annotation found. (parameter #2)错误:未找到改造注释。 (参数#2)
【发布时间】:2015-10-27 12:15:45
【问题描述】:

我有这个接口:

public interface InterfazAguaHttp {

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

剩下的代码是这样的:

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
                            }
                        });

这一切都在一个 try-catch 块中。在捕获中,我收到此错误:

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

我怎样才能摆脱这个错误,并且仍然有我的回调?

谢谢。

【问题讨论】:

  • 将您的方法更改为void 或使用enqueue

标签: android retrofit


【解决方案1】:

把你的接口方法改成这个

public interface InterfazAguaHttp {

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

其余的代码都是这样的

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供参考

【讨论】:

  • 很高兴我能帮上忙。干杯!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-06
  • 2022-07-31
  • 2020-08-11
  • 1970-01-01
  • 2022-01-03
  • 2017-08-26
  • 1970-01-01
相关资源
最近更新 更多