Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestAdapter (retrofit) not resolving in android

So I am trying to use Retrofit for my project. As the site says I have included compile 'com.squareup.retrofit:retrofit:2.0.0-beta1' in build.gradle. I was reading the tutorials from this link . I want to do something similar like this

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

in my project ie make some calls to an API. But restadapter just doesn't get resolved. On hovering on it it simply says symbol can't be resolved. What is happening here ?

like image 951
abkds Avatar asked Sep 06 '15 13:09

abkds


People also ask

What is retrofitting in Android?

Retrofit is type-safe REST client for Android and Java which aims to make it easier to consume RESTful web services. We'll not go into the details of Retrofit 1. x versions and jump onto Retrofit 2 directly which has a lot of new features and a changed internal API compared to the previous versions.


2 Answers

You have two options:

1) Use stable Retrofit 1

This has the RestAdapter class you need.

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

2) Migrate to Retrofit 2

The RestAdapter class was renamed to Retrofit and the API was completely remade. Read more in Jake Wharton's presentation.

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

As of June 30 2016 the latest version is 2.1.0 obtained by

compile 'com.squareup.retrofit2:retrofit:2.1.0' 

Please check http://square.github.io/retrofit/ for updates.

like image 74
Eugen Pechanec Avatar answered Oct 15 '22 11:10

Eugen Pechanec


There is a change in the API in version 2. This is how you do it in this version:

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

Please refer here for more information: Retrofit 2 home page

and these slides: Retrofit 2 presentation

like image 29
Ashkan Sarlak Avatar answered Oct 15 '22 12:10

Ashkan Sarlak