我只是在做一个GET请求,但我得到这个错误:无法为java.util.List的改造2.0.0-β2创建转换
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yomac_000.chargingpoint/com.example.yomac_000.chargingpoint.AllStores}: java.lang.IllegalArgumentException: Unable to create converter for java.util.List<model.Store>
而且是因为这条线的代码:
Call<List<Store>> call = subpriseAPI.listStores(response);
所以,我曾与这行代码想看看它是什么类型:
System.out.println(subpriseAPI.listStores(response).getClass().toString());
但后来我得到了同样的错误,因此不乐我知道它是什么类型。在下面你可以看到我的代码。
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;
}
}
SubpriseAPI.java:
public interface SubpriseAPI {
@GET("api/locations/get")
Call<List<Store>> listStores(@Path("store") String store);
}
Store.java:
public class Store {
String name;
}
我使用的是改造版本2.0.0-β2。
我也有这个问题,我问了改造开发商做出错误这里更有意义https://github.com/square/retrofit/issues/1774。 –