RestAdapter(改装)没有在android中解析

abk*_*kds 27 android retrofit

所以我正在尝试将Retrofit用于我的项目.由于该网站说,我已经包含 compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'build.gradle.我正在阅读此链接中的教程.我想做类似这样的事情

final RestAdapter restadapter = new RestAdapter.Builder().setEndpoint("http://services.hanselandpetal.com").build();

        api flowerapi = restadapter.create(api.class);

        flowerapi.getData(new Callback<List<Flower>>() {
            @Override
            public void success(List<Flower> flowers, Response response) {
                flowerList = flowers;
                adapter adapt = new adapter(getApplicationContext(),R.layout.item_file,flowerList);
                //ListView listView = (ListView) findViewById(R.id.list);
                setListAdapter(adapt);
            }
Run Code Online (Sandbox Code Playgroud)

在我的项目中,即调用API.但是,restadapter只是没有得到resolved.简单地说,在它上面盘旋它symbol can't be resolved.这里发生了什么?

Eug*_*nec 63

您有两种选择:

1)使用稳定的改造1

这是RestAdapter你需要的课程.

compile 'com.squareup.retrofit:retrofit:1.9.0'
Run Code Online (Sandbox Code Playgroud)

2)迁移到Retrofit 2

RestAdapter班更名为Retrofit和API完全重制.阅读Jake Wharton的演讲.

compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'

截至2016年6月30日,最新版本为2.1.0

compile 'com.squareup.retrofit2:retrofit:2.1.0'
Run Code Online (Sandbox Code Playgroud)

访问http://square.github.io/retrofit/获取更新.


Ash*_*lak 29

版本2中的API发生了变化.这是您在此版本中的操作方式:

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.github.com")
    .build();

GitHubService service = retrofit.create(GitHubService.class);
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅此处:Retrofit 2主页

和这些幻灯片:改造2演示文稿


kun*_*roy 8

如果要运行代码,则需要使用旧版本的Retrofit.

compile 'com.squareup.retrofit:retrofit:1.9.0'

但是你正在使用

compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
Run Code Online (Sandbox Code Playgroud)

所以你需要改变这样的代码.

Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.github.com")
.build();`
Run Code Online (Sandbox Code Playgroud)

如需完整的文档,请查看RetroFit square