title: attempt to invoke interface method 'java.util.iterator java.util.list.iterator()' on a null object Volley
body: <p>I am trying to fetch data from API and save it in local database but the problem is sometimes my code works perfectly and sometimes it does not work. It throws iterator exception. I am trying to debug it but not able to find any satisfactory result. Please help. I do not understand why my code run sometimes and sometimes not.</p>
  
  <pre><code>       private void callEventsApi() {
  
      String tag_json_obj = "json_obj_req";
      String url = Constants.GET_EVENTS;
      final SessionManager session = new SessionManager(getActivity());
      final HashMap&lt;String, String&gt; loggedDetail = session.getUserDetail();
  
      pBar.setVisibility(View.VISIBLE);
  
  
      JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
              url, new JSONObject(),
              new Response.Listener&lt;JSONObject&gt;() {
  
                  @Override
                  public void onResponse(JSONObject response) {
  
                      Log.e("event_response", response.toString());
  
                      Gson gson = new Gson();
  
  
                      try {
                          databaseHelper.deleteData();
                          ModelEvent modelEvent;
                          modelEvent = gson.fromJson(response.toString(), ModelEvent.class);
  
  
                          if (modelEvent.getStatus() == 200) {
  
                              String status = response.getString("status");
  
                              JSONArray jsonArray = response.getJSONArray("data");
  
                              Log.e("tag", "instatus: " + jsonArray);
  
                              List&lt;EventData&gt; datumArrayList = new ArrayList&lt;&gt;();
  
                              datumArrayList = Arrays.asList(gson.fromJson(jsonArray.toString(), EventData[].class));
  
                              Log.e("TAG", "onResponse:size " + datumArrayList.size());
  
  
  
                              for (EventData eventData : datumArrayList) {
  
                                  databaseHelper.addEventsDetails(eventData);
                                  Log.e("tag", "onResponse56: " + datumArrayList.size());
  
  
                              }
  
  
                              for (int i = 0; i &lt; datumArrayList.size(); i++) {
  
                                  for (EventProduct eventProduct : datumArrayList.get(i).getProducts()) {
  
  
                                      Integer event_pro_id = datumArrayList.get(i).getEventId();
                                      Integer product_id = eventProduct.getId();
                                      String product_name = eventProduct.getProductName();
  
                                      EventProduct eventProduct1 = new EventProduct();
                                      eventProduct1.setEventId(event_pro_id);
                                      eventProduct1.setId(product_id);
                                      eventProduct1.setProductName(product_name);
                                      databaseHelper.addEventProducts(eventProduct1);
  
  
                                  }
  
  
                              }
  
  
                              for (int i = 0; i &lt; datumArrayList.size(); i++) {
                                  for (Subevent subevent : datumArrayList.get(i).getSubevent()) {
  
                                      Log.e("tag", "onResponse13: " + subevent.getDate() + "&amp;&amp;" + subevent.getId() + "**" +
                                              datumArrayList.get(i).getEventId() + "))" + datumArrayList.get(i).getEventName());
  
                                      Integer event_sub_id = datumArrayList.get(i).getEventId();
                                      Integer sub_event_id = subevent.getId();
                                      String sub_event_name = subevent.getName();
                                      String sub_event_date = subevent.getDate();
  
  
                                      Subevent subevent1 = new Subevent();
                                      subevent1.setEventId(event_sub_id);
                                      subevent1.setId(sub_event_id);
                                      subevent1.setName(sub_event_name);
                                      subevent1.setDate(sub_event_date);
  
                                      databaseHelper.addSubEvents(subevent1);
  
                                  }
                              }
  
                              for (int i = 0; i &lt; datumArrayList.size(); i++) {
                                  for (Subevent subevent : datumArrayList.get(i).getSubevent()) {
                                      for (EventBar eventBar : subevent.getBars()) {
  
                                          Log.e("tag", "onResponse14: " + eventBar.getName() + "&amp;&amp;" + eventBar.getId() + "**" +
                                                  subevent.getId() + "))");
  
                                          Integer subEvent_bar_id = subevent.getId();
                                          Integer bar_id = eventBar.getId();
                                          String bar_name = eventBar.getName();
  
  
                                          EventBar eventBar1 = new EventBar();
                                          eventBar1.setSubEventId(subEvent_bar_id);
                                          eventBar1.setId(bar_id);
                                          eventBar1.setName(bar_name);
  
                                          databaseHelper.addSeBars(eventBar1);
  
  
                                      }
  
                                  }
                              }
  
  
                              netStockApi();
                              Intent in = new Intent(getActivity(), ContainerActivity.class);
                              startActivity(in);
  
  
                          } else {
  
                              Toast.makeText(getActivity(), R.string.some_error_occured, Toast.LENGTH_SHORT).show();
                          }
  
  
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
  
  
                      pBar.setVisibility(View.GONE);
  
                  }
              }, new Response.ErrorListener() {
  
  
          @Override
          public void onErrorResponse(VolleyError error) {
              VolleyLog.e("Error: " + error.getMessage());
                // handle error
              pBar.setVisibility(View.GONE);
          }
      }) {
  
          @Override
          public Map&lt;String, String&gt; getHeaders() throws AuthFailureError {
              HashMap&lt;String, String&gt; headers = new HashMap&lt;String, String&gt;();
              headers.put("Content-Type", "application/json; charset=UTF-8");
              headers.put("Authorization", "Bearer " + loggedDetail.get("api_token"));
              return headers;
          }
      };
  
  
      jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
              100000,
              DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
              DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
  
  
      AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
  }
  </code></pre>