jsonObjectRequest and StringRequest Response Listener are not working after many tries

133 views Asked by At

I took the example code in the documentation, the one from youtube videos. Nothing happens at the new Response. Listener and the onResponse function are not even called. Can't debug it even if I put a breakpoint inside, don't understand what is not working, no error caught in onErrorResponse function or try-catch block.

CODE:

    ListView statlist;
    RecyclerView recyclerView;
    String dcritical, dpositive, dtoday_cases, dtotal_deaths, dtotalcases, dtotal_countries, test;

    public void FetchAPI_Data()
    {
      //  String url = "https://corona.lmao.ninja/v2/all";



        String url  = "https://corona.lmao.ninja/v2/all/";

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    test = response.toString();
                    JSONObject jsonObject = new JSONObject(response.toString());
                    Log.d("JSON", jsonObject.getString("recovered"));

                    String recovered = jsonObject.getString("recovered");
                    Log.d("RECOVERED", recovered.toString());
                    String critical = jsonObject.getString("critical");
                    String positive = jsonObject.getString("active");
                    String today_cases = jsonObject.getString("todayCases");
                    String total_deaths = jsonObject.getString("deaths");
                    String total_countries = jsonObject.getString("affectedCountries");
                    String totalcases = jsonObject.getString("cases");


                    dcritical = critical;
                    dpositive = positive;
                    dtoday_cases = today_cases;
                    dtotal_deaths = total_deaths;
                    dtotal_countries = total_countries;
                    dtotalcases = totalcases;
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(jsonObjectRequest);



        //GlobalStatsData data= new GlobalStatsData(dcritica);
        //return data;


    }

JSON RESPONSE FORMAT

{
    "updated": 1621228955561,
    "cases": 163724238,
    "todayCases": 12591,
    "deaths": 3393440,
    "todayDeaths": 222,
    "recovered": 143348966,
    "todayRecovered": 31533,
    "active": 16981832,
    "critical": 102549,
    "casesPerOneMillion": 21004,
    "deathsPerOneMillion": 435.3,
    "tests": 2324559552,
    "testsPerOneMillion": 297062.96,
    "population": 7825140972,
    "oneCasePerPeople": 0,
    "oneDeathPerPeople": 0,
    "oneTestPerPeople": 0,
    "undefined": 0,
    "activePerOneMillion": 2170.16,
    "recoveredPerOneMillion": 18319.03,
    "criticalPerOneMillion": 13.11,
    "affectedCountries": 222
}
0

There are 0 answers