Android Studio and Volley -JsonArrayRequest Displaying Error

2387 views android
8

here is my code, whenever i try to make the Response to convert to toString() i get the error

private void fetchStoreItems() {
        String url = "https://newsapi.org/v1/articles?source=techcrunch&apiKey=47bdfe44632849b4bdf0c2a9035a68e7";
        JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET,
                url, new com.android.volley.Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                VolleyLog.d("ecardCalled: ", response.toString());
            }
        },new com.android.volley.Response.ErrorListener(){

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d("ecardCalled: ", error.toString());
            }
        });

        MyApplication.getInstance().addToRequestQueue(jsonArrayRequest);
    }

enter image description here

what am i not actually doing Right?

answered question

2 Answers

8

You have to provide json params value if you have any otherwise set it to null

 JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET,
                url,null, new com.android.volley.Response.Listener<JSONArray>() {
            @Override
            ....
            ....
            ...
            //other code

posted this
7

use this code instead of yours:

 private void fetchStoreItems() {
    String url = "https://newsapi.org/v1/articles?source=techcrunch&apiKey=47bdfe44632849b4bdf0c2a9035a68e7";
   JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
       @Override
       public void onResponse(JSONArray response) {
           VolleyLog.d("ecardCalled: ", response.toString());
       }
   }, new Response.ErrorListener() {
       @Override
       public void onErrorResponse(VolleyError error) {
           VolleyLog.d("ecardCalled: ", error.toString());
       }
   });

    MyApplication.getInstance().addToRequestQueue(jsonArrayRequest);
}

posted this

Have an answer?

JD

Please login first before posting an answer.