我正在尝试对网络进行2次顺序调用,其中第二次调用将第一次调用的结果作为参数。我正在尝试使用MVVM和Transformations.switchMap进行操作,但出现异常“ java.lang.IllegalArgumentException:无法为com.rdev.image.obj.FlickrResultSize类创建调用适配器”。有人知道怎么做吗?
override fun onOpen(webSocket: WebSocket) {
super@Listener.onOpen(webSocket)
}
//呼叫网络
public LiveData<ArrayList<String>> getValuesAPI(String url) {
LiveData<ArrayList<String>> ids = AbsentLiveData.create();
LiveData<ArrayList<String>> urls = AbsentLiveData.create();
final MutableLiveData<ArrayList<String>> updatedResult = new MediatorLiveData<>();
//This method waits until it has the data to process
ids = Transformations.switchMap(getValues(url), apiResponse-> {
ArrayList<String> listaIds = new ArrayList<>();
if(apiResponse.isSuccessful()) {
if (apiResponse.body != null) {
FlickrPhotos flickrPhotos = new FlickrPhotos();
flickrPhotos = apiResponse.body.getPhotos();
FlickrResultSize flickrResultSizes = new FlickrResultSize();
for(int i=0;i<flickrPhotos.getPhoto().size();i++){
String id = flickrPhotos.getPhoto().get(i).getId();
String link = Utils.createURL(2,id);
flickrResultSizes = getPhotos(link); -----------I want to call this, but I can't
Timber.d("depois do getPhotos");
listaIds.add(id);
}
updatedResult.postValue(listaIds);
}
}
});
return ids;
}