使用Retrofit2时,为什么会出现"输入okhttp3.Call没有类型参数"?

Yok*_*ich 6 java android android-studio retrofit2 okhttp3

我正在尝试按照Retrofit2 入门和创建Android客户端的本教程.

进口很好

compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
Run Code Online (Sandbox Code Playgroud)

除了一件事,我可以很好地遵循教程.我试图创建GitHubService Interface和我遇到两个问题:Call<V>说它不采取任何类型参数,我也不确定在哪里放Contributor类,因为它是根据教程只声明static,这是否意味着它嵌套在某处?

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;
}
Run Code Online (Sandbox Code Playgroud)

我将Contributor类放在一个单独的文件中并将其公之于众.此外,Call类不会在Android Studio中自动导入,我必须手动选择它,但这是我收到的唯一一个Call(除了Androids手机api)

请帮助我解释为什么我会得到这个错误,从我可以看到没有人有同样的事情所以我错过了一些基本的东西.

Bla*_*elt 14

因此,编译时错误导致您Call从错误的包导入.请检查您的导入并确保您拥有

import retrofit2.Call;
Run Code Online (Sandbox Code Playgroud)

所有与Retrofit相关的导入都应该来自包装retrofit2.

另一方面

 Call contributors(
Run Code Online (Sandbox Code Playgroud)

它无法猜出你想要归来的东西.一个Contributor?一个List<Contributor>可能?例如

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