title: NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
body: <p>I am getting <code>NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference</code> at this line of code.</p>
  
  <pre><code>for (int i = 0; i &lt; jsonArray.length(); i++) {
  </code></pre>
  
  <p>My code,</p>
  
  <pre><code>private List&lt;QuizWrapper&gt; returnParsedJsonObject(String result) {
  
      List&lt;QuizWrapper&gt; jsonObject = new ArrayList&lt;QuizWrapper&gt;();
      JSONObject resultObject = null;
      JSONArray jsonArray = null;
      QuizWrapper newItemObject = null;
      try {
          resultObject = new JSONObject(result);
          System.out.println("Testing the water " + resultObject.toString());
          jsonArray = resultObject.optJSONArray("quiz_questions");
      } catch (JSONException e) {
          e.printStackTrace();
      }
      for (int i = 0; i &lt; jsonArray.length(); i++) {
          JSONObject jsonChildNode = null;
          try {
              jsonChildNode = jsonArray.getJSONObject(i);
              int id = jsonChildNode.getInt("id");
              String question = jsonChildNode.getString("question");
              String answerOptions = jsonChildNode.getString("possible_answers");
              int correctAnswer = jsonChildNode.getInt("correct_answer");
              newItemObject = new QuizWrapper(id, question, answerOptions, correctAnswer);
              jsonObject.add(newItemObject);
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
      return jsonObject;
  }
  </code></pre>
  
  <p>My logcat error,</p>
  
  <pre><code>FATAL EXCEPTION: main
    Process: androidquizapplication.inducesmile.com.itona, PID: 12093
    java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference
        at androidquizapplication.inducesmile.com.itona.QuizActivity.returnParsedJsonObject(QuizActivity.java:246)
        at androidquizapplication.inducesmile.com.itona.QuizActivity.access$1400(QuizActivity.java:37)
        at androidquizapplication.inducesmile.com.itona.QuizActivity$AsyncJsonObject.onPostExecute(QuizActivity.java:201)
        at androidquizapplication.inducesmile.com.itona.QuizActivity$AsyncJsonObject.onPostExecute(QuizActivity.java:167)
  </code></pre>
  
  <p>your help will help me a lot. </p>