Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Java中的API改进中的用法_Java_Github_Retrofit_Retrofit2_Github Api - Fatal编程技术网

使用Java中的API改进中的用法

使用Java中的API改进中的用法,java,github,retrofit,retrofit2,github-api,Java,Github,Retrofit,Retrofit2,Github Api,根据官方网站的信息,我添加了最新的依赖性并开始开发 首先,我用我感兴趣的数据创建了模型: public class Data{ String parametr1; //geters and setters ommited } 第二步是添加服务: public interface GitHubService { @GET("/repos/{owner}/{repo}") Call<Data> repoInfos(@Path("user") String

根据官方网站的信息,我添加了最新的依赖性并开始开发

首先,我用我感兴趣的数据创建了模型:

public class Data{
    String parametr1;
    //geters and setters ommited
}
第二步是添加服务:

public interface GitHubService {
    @GET("/repos/{owner}/{repo}")
    Call<Data> repoInfos(@Path("user") String owner, @Path("repo") String repo);

    Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.github.com/").build();
}
对于maven依赖项:

<dependency>
    <groupId>com.squareup.retrofit2</groupId>
    <artifactId>converter-gson</artifactId>
    <version><latest-version></version>
</dependency>

应该可以了。

您签出了吗?我使用的是maven,不是grandle,但它可能会解决我的问题,请给我一点时间检查一下。我添加了此依赖性,但还有另一个问题。什么样的问题出现了意外错误(type=Internal Server error,status=500)。无法将Refught2.OkHttpCall转换为model.Data。以下是完整的错误跟踪:。服务器错误我无法帮助抱歉。顺便说一句,不要在你自己之后多次发表评论,只要编辑上一条消息,除非其他人在你之后发布。我将返回类型从Data更改为Call,现在没有错误,但它打印的不是我想要的信息:{“Cancelled”:false,“executed”:false}。好的,我将尝试编辑以前的消息。:)
java.lang.IllegalArgumentException: Could not locate ResponseBody converter for class model.Data.
<dependency>
    <groupId>com.squareup.retrofit2</groupId>
    <artifactId>converter-gson</artifactId>
    <version><latest-version></version>
</dependency>
Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(Constants.API_BASE_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .build();