I tried to reach to the forecast data but failed, NullPointerException
and sometimes crash. because i fail to reach or retrieve data from item -> forecast -> {data}
.
At Item class:
condition = new Condition();
condition.jsonPopulate("condition");
At Condition Class :
void jsonPopulate(data){
temp = data.optString("temp");
}
I got data at condition class successfully,
But why i cant do the same for forecast since forecast and condition are siblings.
Since forecast has array object so I tried like below retrieve data :
Context Item class sending object of forecast Code of Item class like below.
forecast= new Condition();
forecast.jsonPopulate("forecast");
Context Forecast Class when retrive data from forecast object Code of forecast class like below.
private String day;
private String high;
private String low;
ArrayList<ForecastDetails>fdetails;
public void jsonPopulate(data){
for(i=0; i<data.length(); i++){
day = data.optString("day");
high = data.optString("high");
low = data.optString("low");
fdetails.add(day);
fdetails.add(high);
fdetails.add(low);
}
}
and try to keep in a ArrayList<ForecastDetails>;
but failed, anyone has can suggest me about how to retrieve forecast data from item object of Yahoo weather.
JSONObject d = new JSONObject(data);
for(i=0; i<d.length(); i++)
{
day = d.getString("day");
high = d.getString("high");
low = d.getString("low");
fdetails.add(day);
fdetails.add(high);
fdetails.add(low);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.