I work with MVP Architecture I get information through an API. In the MODEL LEVEL, I have List I want to pass this List into PRESENTER LEVEL.
When I create a function to resolve this issue I got an error message "NULL ERROR"
Here is my code :
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;
}
}
}
interface method
public CountryModel Get_Wather_Informations(int position);
model code
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);
}
When I try to get an object from this list ( PRESENTER LAYER ) I get a null!
CountryModel COUNTRY_OBJ = new CountryModel();
COUNTRY_OBJ = MODEL.Get_Wather_Informations(0);