我正在尝试按照本教程进行 Retrofit2 Getting Started and Create an Android Client .
导入没问题
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
除了一件事,我可以很好地按照教程进行操作。我正在尝试创建 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;
}
我将 Contributor 类放在一个单独的文件中并将其公开。 此外,Call 类不会在 Android Studio 中自动导入,我必须手动选择它,但它是我得到的唯一 Call(Androids phone api 除外)
请帮助我解决为什么会出现此错误,据我所知,周围没有人遇到同样的事情,所以我遗漏了一些基本的东西。
最佳答案
根据您遇到的编译时错误,您确实导入了 Call
来自错误的包裹。请检查您的导入并确保您有
import retrofit2.Call;
所有与 Retrofit 相关的导入都应该来自包 retrofit2
.
另一方面
Call contributors(
它无法猜测您要返回什么。 Contributor
?一个List<Contributor>
也许?例如
public interface GitHubClient {
@GET("/repos/{owner}/{repo}/contributors")
Call<List<Contributor>> contributors(
@Path("owner") String owner,
@Path("repo") String repo
);
}
关于java - 为什么我在使用 Retrofit2 时得到 "Type okhttp3.Call does not have type parameters"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35176599/