title: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
body: <p>I need to parse <code>json</code> from <code>String builder</code>, but I get this error:</p>
  
  <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
  </code></pre>
  
  <p>I don't know why <code>stringBuilder.toString()</code> give me the array with objects!</p>
  
  <p>Here is my code:</p>
  
  <pre><code>try {
      // HttpResponse is an interface just like HttpPost.
      //Therefore we can't initialize them
      HttpResponse httpResponse = httpClient.execute(httpPost);
  
      // According to the JAVA API, InputStream constructor do nothing.
      //So we can't initialize InputStream although it is not an interface
      InputStream inputStream = httpResponse.getEntity().getContent();
  
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
  
      BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
  
      StringBuilder stringBuilder = new StringBuilder();
  
      String bufferedStrChunk = null;
  
      while((bufferedStrChunk = bufferedReader.readLine()) != null){
          stringBuilder.append(bufferedStrChunk);
      }
  
      // return stringBuilder.toString();
      System.out.println("EHEH"+stringBuilder.toString());
  
  
      JSONArray mainObject = null;
      try {
          mainObject = new JSONArray(stringBuilder.toString());
      } catch (JSONException e) {
          e.printStackTrace();
      }
  
      for (int i = 0; i &lt; mainObject.length(); i++) {
          JSONObject object = null;
          try {
              object = mainObject.getJSONObject(i);
          } catch (JSONException e) {
              e.printStackTrace();
          }
          try {
              Video video=new Video();
              String url = object.getString("url");
  
              String titolo = object.getString("titolo");
              String sottotitolo = object.getString("sottotitolo");
              String data = object.getString("date");
              //video.setId(idd4);
              System.out.println("CAZZO:"+video.getId());
              video.setPic(url);
              video.setTitolo(titolo);
              video.setSottotitolo(sottotitolo);
              video.setData(data);
  
              videoList.add(video);
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>Can someone help me?</p>
  
  <p>JSON RESPONSE:</p>
  
  <p><img src="https://i.stack.imgur.com/NtRkK.png" alt="enter image description here"></p>