title: How to parse JSON response from API
body: <p>I am trying to fetch json data and put it in a ListView. I was following a tutorial and tried to implement this. Problem is: the tutorial was based on <code>AppCompatActivity</code> and I am trying to add it in a <code>Fragment</code> (Tab):</p>
  
  <pre><code>public class InstallsTab extends Fragment{
      ListView installs;
      String url = "http://localhost/android.php";
      ProgressBar dialog;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          final View rootView = inflater.inflate(R.layout.installs_tab, container, false);
  
          installs = rootView.findViewById(R.id.install_list);
  
          dialog = new ProgressBar(getActivity().getApplicationContext());
          dialog.setVisibility(View.VISIBLE);
  
          StringRequest request = new StringRequest(url, new Response.Listener&lt;String&gt;() {
              @Override
              public void onResponse(String string) {
                  parseJsonData(string);
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError volleyError) {
                  Toast.makeText(getActivity().getApplicationContext(), "Some error occurred!!", Toast.LENGTH_SHORT).show();
                  dialog.setVisibility(View.GONE);
              }
          });
  
          RequestQueue rQueue = Volley.newRequestQueue(getActivity().getApplicationContext());
          rQueue.add(request);
  
          return rootView;
      }
  
      void parseJsonData(String jsonString) {
          try {
              JSONObject object = new JSONObject(jsonString);
              JSONArray fruitsArray = object.getJSONArray("fruits");
              ArrayList al = new ArrayList();
  
              for(int i = 0; i &lt; fruitsArray.length(); ++i) {
                  al.add(fruitsArray.getString(i));
              }
  
              ArrayAdapter adapter = new ArrayAdapter(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, al);
              installs.setAdapter(adapter);
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          dialog.setVisibility(View.GONE);
      }
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/XllC4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XllC4.jpg" alt="enter image description here"></a></p>
  
  <p>And the app is crashing on run.</p>