Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
Android 改装2.0:无法为类创建调用适配器_Android_Json_Retrofit - Fatal编程技术网

Android 改装2.0:无法为类创建调用适配器

Android 改装2.0:无法为类创建调用适配器,android,json,retrofit,Android,Json,Retrofit,我正在使用改装版2.0-beta1。如何发出简单的同步请求并将JSON响应反序列化为POJO列表?这是我的界面: public interface ArticlesAPI { @GET("/articles") List<ArticleResource> getArticles(); } 但我得到了这个错误: 根据您发布的代码,您必须从 List getArticles() 到 调用getArticles() 您可能还需要显式调用addConverterFactor

我正在使用改装版2.0-beta1。如何发出简单的同步请求并将JSON响应反序列化为POJO列表?这是我的界面:

public interface ArticlesAPI {
    @GET("/articles")
    List<ArticleResource> getArticles();
}
但我得到了这个错误:


根据您发布的代码,您必须从

List getArticles()

调用getArticles()


您可能还需要显式调用
addConverterFactory
来设置要使用的转换器

如果您使用的是
kotlin
coroutines
且函数不是
suspend
函数,也可能会出现此问题

public interface ArticlesAPI {
 @GET("url.../habits/progress/")
    suspend fun getHabitsTasks(): BaseResponse<HabitResModel>
}
公共接口ArticlesAPI{
@获取(“url…/习惯/进度/”)
挂起getHabitsTasks():BaseResponse
}

在build.gradle文件中将改型2版本更改为最新版本

implementation "com.squareup.retrofit2:retrofit:2.9.0"

你是如何实例化这个改型.Builder的?我已经发布了代码。它仍然不工作。它是相同的错误吗?是的,相同的一个。虽然我使用了JacksonConverterFactory。它应该可以工作,是吗?你能解释一下为什么吗?@Radu为什么是什么?为什么改型2.0决定把所有东西都封装在一个调用中。我认为这是为了封装同步/异步行为?@Radu,这是很有可能的。你应该要求square成为100%的sureKa chow!我忘了挂起前缀。谢谢!:)为什么是安卓?为什么?你好@Rahul,我是MVVM和corotuines的新手,我也遇到了同样的问题。你能帮我吗?这是我的代码,这对我有用
Retrofit retrofit = (new Retrofit.Builder()).baseUrl(this.baseUrl).build();
ArticlesAPI api = retrofit.create(ArticlesAPI.class);
public interface ArticlesAPI {
 @GET("url.../habits/progress/")
    suspend fun getHabitsTasks(): BaseResponse<HabitResModel>
}
implementation "com.squareup.retrofit2:retrofit:2.9.0"