任何人都可以幫助我將arraylist
帶出循環。如果我把它拿出來,它會隨着數組的越界而變空。這裏是我的代碼:無法將json值打印到整數數組列表中?是保存在那裏,但無法退出循環?
public void collapse() {
corequestQueue= Volley.newRequestQueue(getApplicationContext());
String url="http://192.168.43.208/online/json.php";
JsonObjectRequest jsonObjectRequest3=new JsonObjectRequest(Request.Method.GET, url,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray=response.getJSONArray("server_responce");
for (int i=0;i<=jsonArray.length();i++){
JSONObject admin=jsonArray.getJSONObject(i);
solution.add(Integer.valueOf(admin.getString("sno")));
//if i do like this the values prints here in the toast.
//Toast.makeText(User_Login.this, "hello"+solution.get(0), Toast.LENGTH_SHORT).show();
//printing the toast anywhere out of the block gives error.. as assay out of bound 0 on index size 0.. help me guys
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Volly","error");
}
}
);
corequestQueue.add(jsonObjectRequest3);
Toast.makeText(User_Login.this, "hello"+solution.get(0), Toast.LENGTH_SHORT).show();
}
最後一行給我的錯誤,因爲它的未來是空的,我不能把數組列表以外的任何地方。當它在循環內部並且值正在增加時,它是完美的。我已經檢查過,只有一件事是我不能把它拿出來?
後,其中u已宣佈的解決方案列表? – Raghavendra
請發佈,你應該收到 –