任何人都可以幫忙。當我想在另一個活動中獲得溫度時,我得到的值爲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