0

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?

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

1

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.