0

I'm trying to parse json using volley but I cant receive the data. Assume that I received the data. I send that to the recycler view. But I'm not sure about using the JSONObject. Maybe there is a error I couldn't see it. And this is my json website "https://docs.spacexdata.com/#3d6e6f8a-a459-4265-84b1-e2b288a58537".

private void parseJson() {
        String url = "https://docs.spacexdata.com/#d65a7f85-e0c7-41ce-b41d-9ad20a238d90";

        JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                try {
                for(int i = 0; i < response.length(); i++) {
                    JSONObject capsuleObject = response.getJSONObject(i);

                    String details = capsuleObject.getString("details");
                    String type = capsuleObject.getString("type");
                    mCapsuleList.add(new Capsule("null", "null", "null", "null", 0, 0, type, details, 0));
                }
                    mCapsuleAdapter = new CapsuleAdapter(CapsuleFragment.this.getContext(), mCapsuleList);
                    mRecyclerView.setAdapter(mCapsuleAdapter);
                } catch (JSONException e) {
                        e.printStackTrace();
                    }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        });
        mRequestQueue.add(request);
    } 

There is a lot of value in json but I just want to receive "type" and "detail". It says my request is null. So how can i parse this?

  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – a_local_nobody Jan 03 '21 at 15:29
  • Thanks for answer. But no. I can't receive data from json object. Normally I can't use it. That's why it says null pointer exception. Main thing is how to parse json using volley. – Burak Karaduman Jan 03 '21 at 15:35
  • your question title (which isn't really a question, just the stack trace) is saying that you're trying to use RequestQueue.add on a null object. i don't see in the code you've posted where you're making an instance of `mRequestQueue` – a_local_nobody Jan 03 '21 at 15:37
  • Let me edit it. And mRequestQueue is bottom of the code. – Burak Karaduman Jan 03 '21 at 15:40
  • `And mRequestQueue is bottom of the code` that does not answer my question of _where are you making an instance of it_? – a_local_nobody Jan 03 '21 at 15:47
  • In the onCreateView. `mRequestQueue = Volley.newRequestQueue(Objects.requireNonNull(this.getContext()));` – Burak Karaduman Jan 03 '21 at 15:53

0 Answers0