我使用MVP体系结构,我通过API获得信息。在MODEL LEVEL中,我有一个列表,我想将此列表传递到PRESENTER LEVEL中。
当我创建一个函数来解决此问题时,出现错误消息“ NULL ERROR”
这是我的代码:
package com.example.lenovo.myapplication.Model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class CountryModel {
private String City;
private String Country;
private String Degree;
@SerializedName("posts")
public String getCity() {
return City;
}
public String getCountry() {
return Country;
}
public String getDegree() {
return Degree;
}
public void setCity(String city) {
City = city;
}
public void setCountry(String country) {
Country = country;
}
public void setDegree(String degree) {
Degree = degree;
}
public class ResultModel {
List<CountryModel> posts;
public List<CountryModel> getCountryModels() {
return posts;
}
public void setCountryModels(List<CountryModel> countryModels) {
this.posts = countryModels;
}
}
}
接口方法
public CountryModel Get_Wather_Informations(int position);
型号代码
connection.enqueue(new Callback<CountryModel.ResultModel>() {
@Override
public void onResponse(Call<CountryModel.ResultModel> call, Response<CountryModel.ResultModel> response) {
countryModels = response.body().getCountryModels();
for (int i = 0; i < countryModels.size(); i++) {
CountryModel ye = new CountryModel();
ye.setCountry(countryModels.get(i).getCountry());
ye.setCity(countryModels.get(i).getCity());
ye.setDegree(countryModels.get(i).getDegree());
ARRAYS.add(ye);
Log.e("array size ", String.valueOf(ARRAYS.size()));
// Log.e("Size", String.valueOf(arrayList.size()));
}
@Override
public CountryModel Get_Wather_Informations(int position) {
return countryModels.get(position);
}
当我尝试从该列表(PRESENTER LAYER)中获取对象时,我得到的是空值!
CountryModel COUNTRY_OBJ = new CountryModel();
COUNTRY_OBJ = MODEL.Get_Wather_Informations(0);