Не получая никакого ответа от залпа - PullRequest
0 голосов
/ 29 октября 2019

Я не получаю практически никакого ответа.

Это для школьного проекта, я не получаю никакого ответа от залпа, что бы то ни было, пожалуйста, помогите.

Я пробовал разныеверсии Volley, я пытался добавить доступ к Интернету в манифест, без помощи.

        RequestQueue queue = Volley.newRequestQueue(this);
        api();



        public void api(){

        String new_url = "http://api.myjson.com/bins/kp9wz";



        System.out.println(new_url);

        final JsonObjectRequest request = new 
        JsonObjectRequest(Request.Method.GET, new_url, null, new 
        Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    JSONArray jsonArray = response.getJSONArray("employees");
                    devices = new ArrayList<>();

                    for(int i = 0; i < jsonArray.length(); i++){
                        JSONObject jsonObject = jsonArray.getJSONObject(i);

                        String deviceId = jsonObject.getString("firstname");
                        String deviceName = jsonObject.getString("age");
                        String deviceStatus = jsonObject.getString("mail");


                        System.out.println(jsonObject.getString("firstname"));
                        System.out.println(jsonObject.getString("age"));
                        System.out.println(jsonObject.getString("mail"));

                        devices.add(new 
           Device(deviceName,deviceStatus,deviceId));
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
                System.out.println("WTF");
            }
             });
             }

´´´


I don't get anything
I expect it to save the data into the arraylist and sout, each field in the for loop

1 Ответ

0 голосов
/ 05 ноября 2019

Я был достаточно глуп, чтобы не относить запрос к RequestQueue, я решил его.

...