1

I'm trying to send a simply JSON request using Volley JsonObjectRequest. After getting the JSON response, I would like to update a value called valoreConvertito, but the JSON response is null and consequently valoreConvertito remains zero.

private void convertiREST(final Double valoreDaConvertire, String valuta){

    final TextView textView = (TextView) findViewById(R.id.text);
    RequestQueue queue = Volley.newRequestQueue(this);
    String url =COMPLETEURL;

    valoreConvertito = 0.0;

    JsonObjectRequest objectRequest = new JsonObjectRequest(
            Request.Method.GET,
            url,
            null,
            new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            Log.e("Rest response    ", response.toString());
                            valoreConvertito = response.getJSONObject("quotes").getDouble("valuta");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e("Rest response", error.toString());
                    }
                });
        queue.add(objectRequest);
    }

I've even followed the suggestions in another post (Volley JsonObjectRequest response) but I still got JSON response null.

Using the debugger it seems that the program doesn't enter neither in onResponse nor in ErrorListener.

Muntasir Aonik
  • 1,800
  • 1
  • 9
  • 22
DarkCoffee
  • 930
  • 3
  • 17
  • 30

1 Answers1

0

After adding the row queue.add(objectRequest); I notice in Logcat the HTTP traffic not permitted error and I've solved my issue following Android 8: Cleartext HTTP traffic not permitted post.

DarkCoffee
  • 930
  • 3
  • 17
  • 30