任何人都可以帮忙。当我想在另一个活动中获得温度时,我得到的值为0. 在onResponse
我尝试设置温度并将其设置。我不知道这个问题。从班级获取价值活动?
private double temperature;
public double getTemperature() {
return temperature;
}
public JSONparser(Context context, String city) {
RequestQueue queue = Volley.newRequestQueue(context);
String url = "http://api.openweathermap.org/data/2.5/weather?q=" + city;
JsonObjectRequest jsObjRequest = new JsonObjectRequest(
Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// TODO Auto-generated method stub
try {
temperature = (response.getJSONObject("main")
.getDouble("temp"));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
});
queue.add(jsObjRequest);
}
尝试改变'temperature'到一个静态成员,如果有效的话。然后,实际上有另一个实例正在创建某处 – Keerthivasan