无法为java.util.List改型2.0.0-beta2创建转换器

无法为java.util.List改型2.0.0-beta2创建转换器,java,android,retrofit,Java,Android,Retrofit,我正在执行一个GET请求,但出现以下错误: java.lang.RuntimeException:无法启动活动组件信息{com.example.yomac_000.chargingpoint/com.example.yomac_000.chargingpoint.AllStores}:java.lang.IllegalArgumentException:无法为java.util.List创建转换器 这是因为这一行代码: Call<List<Store>> call = s

我正在执行一个GET请求,但出现以下错误:

java.lang.RuntimeException:无法启动活动组件信息{com.example.yomac_000.chargingpoint/com.example.yomac_000.chargingpoint.AllStores}:java.lang.IllegalArgumentException:无法为java.util.List创建转换器

这是因为这一行代码:

Call<List<Store>> call = subpriseAPI.listStores(response);
但是我得到了同样的错误,所以它不让我知道它是什么类型。在下面你可以看到我的代码

StoreService.java:

public class StoreService {

    public static final String BASE_URL = "http://getairport.com/subprise/";
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .build();

    SubpriseAPI subpriseAPI = retrofit.create(SubpriseAPI.class);
    String response = "";

    public List<Store> getSubprises() {

        Call<List<Store>> call = subpriseAPI.listStores(response);

        try {
            List<Store> listStores = call.execute().body();

            System.out.println("liststore "+ listStores.iterator().next());
            return listStores;
        } catch (IOException e) {
            // handle errors
        }
        return null;
    }
}

我正在使用改装版2.0.0-beta2。

在2+版本中,您需要通知转换器

public interface SubpriseAPI {
     @GET("api/locations/get")
     Call<List<Store>> listStores(@Path("store") String store);
}
转换器

默认情况下,改型只能将HTTP主体反序列化为OkHttp主体 ResponseBody类型,它只能接受其RequestBody类型 @身体

可以添加转换器以支持其他类型。六兄弟模块 为方便起见,调整流行的序列化库

Gson:com.squareup.改装:转换器Gson-Jackson:com.squareup.改装:转换器Jackson
Moshi:com.squareup.改装:变矩器Moshi
Protobuf:com.squareup.改装:转换器Protobuf
电线:com.squareup.改装:转换器电线
simplexml:com.squareup.Reformation:converter simplexml

所以


这一个对我有用
compile'com.squareup.reformation:converter gson:2.0.0-beta2'
你也可以通过这个compile'com.squareup.reformation2:converter gson:2.0.0'来添加它。你还需要将Moshi实例传递到MoshiConverterFactory.create()方法如果您使用的是自定义适配器,我也遇到了这个问题,我要求改装开发人员在这里使错误更有意义。
public interface SubpriseAPI {
    @GET("api/locations/get")
    Call<List<Store>> listStores(@Path("store") String store);
}
public class Store {
    String name;
}
public interface SubpriseAPI {
     @GET("api/locations/get")
     Call<List<Store>> listStores(@Path("store") String store);
}
@GET("api/locations/{store}")
Call<List<Store>> listStores(@Path("store") String store);
// Square libs, consume Rest API
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'
String baseUrl = "" ;
Retrofit client = new Retrofit.Builder()
    .baseUrl(baseUrl)
    .addConverterFactory(GsonConverterFactory.create())
    .build();