java - 为什么我在使用 Retrofit2 时得到 "Type okhttp3.Call does not have type parameters"?

标签 java android android-studio retrofit2 okhttp

我正在尝试按照本教程进行 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/

相关文章:

java - Spring使用用户名和密码连接到mongodb

Java + Spring 启动 : I am trying to add CacheControl header to ResponseEntity

android - 电话 - 如何进行设置以创建 PhoneGap 应用程序

android - 带有图像的 UrlEncodedFormEntity 时内存不足

android - float 操作按钮图标不在中心

java - Reg - 单元测试和技术知识

java - 改造:使用 JSON 数组发送 POST 请求

java - 应用程序正在等待调试器

java - 静态变量字段在调试器中不可见

java - 如何在用户编辑后获取 EditText 的值?