【问题标题】:Retrofit override method failure改造覆盖方法失败
【发布时间】:2015-10-22 15:26:48
【问题描述】:

我是 android 编程新手,我正在尝试通过改造连接到服务器并获取一些数据。我做了一个小例子来检查它是否会返回一些数据。首先有一个问题,我什至不知道我是否编写了代码来做我想做的事情,其次我得到了错误:

“错误:(64, 52) 错误: 不是抽象的并且不会覆盖回调中的抽象方法失败(RetrofitError)” 和 2 个错误“错误:(67, 13) 错误:方法没有覆盖或实现超类型中的方法”

这是我的代码

 public class MainActivity extends ListActivity{
public static final String ENDPOINT = "http://tinoba.hostzi.com";
List<Jelovnik> jelovnik;
Button gumb;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    gumb = (Button)findViewById(R.id.gumb);



}

public void stisni(View view) {
    RestAdapter adapter = new RestAdapter.Builder()
            .setEndpoint(ENDPOINT)
            .build();
    JelovnikAPI api = adapter.create(JelovnikAPI.class);
    api.getFeed(new Callback<List<Jelovnik>>() {


        @Override
        public void onResponse(Response<List<Jelovnik>> response, Retrofit retrofit) {
            jelovnik = response.body();
            gumb.setText(jelovnik.get(0).getIme().toString());
        }

        @Override
        public void onFailure(Throwable throwable) {

        }
    });
}

} 还有我的改装界面

public interface JelovnikAPI {
@GET("/read.php")
public void getFeed(Callback<List<Jelovnik>> response);

}

【问题讨论】:

    标签: java android retrofit


    【解决方案1】:

    您使用的Callback 的版本来自Retrofit 2,您仍在使用Retrofit 1.xCallback 有两种方法,failuresuccess。你的回调应该是这样的

    new Callback<List<Jelovnik>>() {
    
    
        @Override
        success(List<Jelovnik> t, Response response) {
    
        }
    
        @Override
        public void failure(RetrofitError error) {
    
        }
    });
    

    【讨论】:

    • 谢谢,我已经导入了 2 个版本,这就是问题
    【解决方案2】:

    Throwable 替换为RetrofitError

    @Override
    public void onFailure(RetrofitError retrofitError) {
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-08
      • 2021-06-23
      • 2014-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 2015-01-19
      相关资源
      最近更新 更多