我正在尝试访问X
函数内部的变量,但我似乎无法访问它。我有一个函数“Action()”
public void Action(){
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
try {
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://www.xxxx.com/xxxx.php",
postParameters);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String result = response.toString();
//parse json data
try {
returnString = "";
JSONArray jArray = new JSONArray(result);
for (int i=0; i<jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag","id: "+json_data.getInt("id")+
", name: "+json_data.getString("name")+
", sex: "+json_data.getInt("sex")+
", birthyear: "+json_data.getInt("birthyear"));
X = json_data.getInt("birthyear");
returnString += "\n" + json_data.getString("Time") + " -> "+ json_data.getInt("Value");
}
} catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
} catch(Exception e){
Log.e("log_tag","Error in Display!" + e.toString());;
}
}
}
我希望能够在方法之外访问变量“X”,但它一直告诉我没有声明 X。