Android Запрос на получение Volley, мой onResponse никогда не вызывается - PullRequest
0 голосов
/ 13 июля 2020

Я знаю, что этот вопрос задавали несколько раз, и я перепробовал все решения, однако, похоже, ничего не работает. Мой метод:

    public static LocationGeoData getLocationGeoData(Location location){

        RequestQueue requestQueue = Volley.newRequestQueue(MyApplication.getAppContext());
        Date dateNow = new Date();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy.MM.dd");

        String url = "MYCORRECTURL";
        Log.d("geoData", "In getGeoData  " + url); // this is called and logs
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url,
                null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {

                        Log.d("geoData", "inside the response");// this never gets called

                        try {
                            JSONObject jsonObject = response.getJSONObject("data");
                            for(int i = 0; i <jsonObject.length(); i++){
                                JSONObject heading = jsonObject;
                                if(heading.getString("field-value").equals("field-value")){
                                    JSONObject totIntensity = heading.getJSONObject("total-intensity");
                                    JSONObject declination = heading.getJSONObject("declination");
                                    JSONObject inclination = heading.getJSONObject("inclination");

                                    int totalIntensity = totIntensity.getInt("value");
                                    double declinationValue = declination.getDouble("value");
                                    double inclinationValue = inclination.getDouble("value");

                                    locationGeoData = new LocationGeoData(totalIntensity, declinationValue, inclinationValue);

                                }
                            }
                        } catch (JSONException e) {
                            Log.d("geoData", "Error recorded");//never called
                            e.printStackTrace();
                        }

                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d("geoData", "Error recorded");// never called
            }

        });
        requestQueue.add(request);
        return locationGeoData;
    }

Второе сообщение журнала внутри ответа никогда не вызывается, я не получаю сообщений об ошибках, мой URL-адрес работает, и я могу видеть JsonOBject в браузере при тестировании, но ответ никогда не вызывается в моем методе. Может ли кто-нибудь посоветовать мне, что я делаю не так?

...