对于初学者来说,Rest API比ConnectionRequest更容易使用。但是在模拟器上它运行良好但是在部署apk时我得到java.util.ArrayList不能转换为java.util.HashMap。为什么它在模拟器上运行并且在APP上失败,最重要的是如何解决这个问题。请参阅随附的代码段
List<Shift> shifts = new ArrayList<>();
Map<String, Object> result = (Map<String, Object>) Rest.get(new UrlManager().getShiftsAvailable())
.acceptJson().getAsJsonMap().getResponseData();
Iterator<Map.Entry<String, Object>> itr = result.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<String, Object> entry = itr.next();
Log.p("Key: "+entry.getKey()+" Value: "+entry.getValue());
Iterator<Map.Entry<String, Object>> itr1 = (Iterator<Map.Entry<String, Object>>) entry;
LinkedHashMap<String,String> hm = (LinkedHashMap<String,String>) entry.getValue();
Shift shift = new Shift(hm.get("id"), hm.get("createddate"),
hm.get("start_time"), hm.get("end_time"),
hm.get("driver_locations"), hm.get("shift_times"), hm.get("required_drivers"), hm.get("standby_drivers"), hm.get("check_in_minutes"));
shifts.add(shift);
}