在使用Retrofit進(jìn)行網(wǎng)絡(luò)請(qǐng)求時(shí)出現(xiàn)了以下異常:
java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.fr.konwledge.bean.TestBean
泛型解析錯(cuò)誤褂微。最初我的JavaBean類的寫法如下:
public class TodayListBean {
private boolean isError;
private ResultsBean results;
private List<String> category;
public boolean isError() {
return isError;
}
public ResultsBean getResults() {
return results;
}
public List<String> getCategory() {
return category;
}
public static class ResultsBean<T> {
private List<T> Android;
private List<T> App;
private List<T> iOS;
public List<T> getAndroid() {
return Android;
}
public void setAndroid(List<T> android) {
Android = android;
}
public List<T> getApp() {
return App;
}
public void setApp(List<T> app) {
App = app;
}
public List<T> getiOS() {
return iOS;
}
public void setiOS(List<T> iOS) {
this.iOS = iOS;
}
}
}
后改成如下,解決了問題园爷。
public class TodayListBean<T> {
private boolean isError;
private ResultsBean<T> results;
private List<String> category;
public boolean isError() {
return isError;
}
public ResultsBean<T> getResults() {
return results;
}
public List<String> getCategory() {
return category;
}
public static class ResultsBean<T> {
private List<T> Android;
private List<T> App;
private List<T> iOS;
public List<T> getAndroid() {
return Android;
}
public void setAndroid(List<T> android) {
Android = android;
}
public List<T> getApp() {
return App;
}
public void setApp(List<T> app) {
App = app;
}
public List<T> getiOS() {
return iOS;
}
public void setiOS(List<T> iOS) {
this.iOS = iOS;
}
}
}