The first map gives the size 3, everything is ok. But the one that is filled from the database always has a size of 0, there are no duplicate keys and values. The data from the database itself is normal.
hashmap.put(1,"1"); hashmap.put(2,"2"); hashmap.put(3,"3"); hashmap.size(); requestQueue= Volley.newRequestQueue(this); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try{ JSONArray jsonArray = response.getJSONArray("JUDGES"); for (int i=0;i>jsonArray.length();i++){ JSONObject judges = jsonArray.getJSONObject(i); String name = judges.getString("J_NAME"); int jid = judges.getInt("ID"); hmjudges.put(jid,name); hmjudges.size(); } }catch (JSONException e){e.printStackTrace();} } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } }); requestQueue.add(jsonObjectRequest); UPD With ArrayList everything works.
hashmap.put(1,"1"); hashmap.put(2,"2"); hashmap.put(3,"3"); hashmap.size(); final List<String> names = new ArrayList<String>(); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, "http://full-version.ru/select_judge/judges.php", new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try{ JSONArray jsonArray = response.getJSONArray("JUDGES"); for (int i=0;i<jsonArray.length();i++){ JSONObject judges = jsonArray.getJSONObject(i); String name = judges.getString("J_NAME"); int jid = judges.getInt("ID"); names.add(name); hmjudges.put(jid,name); hmjudges.size(); } }catch (JSONException e){e.printStackTrace();} } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } }); requestQueue= Volley.newRequestQueue(this); requestQueue.add(jsonObjectRequest);