Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get "Type okhttp3.Call does not have type parameters" when using Retrofit2?

I am trying to follow this tutorial for Retrofit2 Getting Started and Create an Android Client.

The imports are fine

compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'

and I can follow the tutorial fine except for one thing. I am trying to create the GitHubService Interface and I run into two problems: The Call<V> says that it doesn't take any type parameters and I am also unsure where to put the Contributor class since it's according to the tutorial only declared as static, does that mean it's nested somewhere?

import okhttp3.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;

public interface GitHubClient {
    @GET("/repos/{owner}/{repo}/contributors")
    Call<List<Contributor>> contributors(
        @Path("owner") String owner,
        @Path("repo") String repo
    );
}

static class Contributor {
    String login;
    int contributions;
}

I have the Contributor class in a separate file and have it as public. Also, the Call class does not import automatically in Android Studio, I have to select it manually, but it's the only Call I got (except for Androids phone api)

Please help me with why I get this errors, from what I can see there is no one around with the same thing so I am missing something fundamental.

like image 757
Yokich Avatar asked Feb 03 '16 12:02

Yokich


1 Answers

Accordingly to the compile time error you are getting you did import Call from the wrong package. Please, check your import and be sure that you have

import retrofit2.Call;

everything Retrofit related import should be from the package retrofit2.

On the other hand

 Call contributors(

it can't guess what you want to return. A Contributor ? a List<Contributor> maybe? E.g.

public interface GitHubClient {
    @GET("/repos/{owner}/{repo}/contributors")
    Call<List<Contributor>> contributors(
        @Path("owner") String owner,
        @Path("repo") String repo
    );
}
like image 146
Blackbelt Avatar answered Nov 14 '22 23:11

Blackbelt