title: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference on Volley while executing Swiperefresh Android
body: <p>i am having this error <code>java.lang.NullPointerException:</code> Attempt to invoke virtual method <code>int java.lang.String.length()</code> on a null object reference while executing the <code>onRefresh</code> in Android. when i fetch data outside <code>onRefresh</code> method it is fine.</p>
  
  <p>here is my Volley Request</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>final String ticketUrl = "http";
          StringRequest getTicket = new StringRequest(Request.Method.POST, ticketUrl,
                  new Response.Listener&lt;String&gt;() {
                      @Override
                      public void onResponse(String response) {
                          try {
                              JSONObject ticketObj = new JSONObject(response);
                              JSONArray ticketArray = ticketObj.getJSONArray("a");
                              for (int i = 0 ; i &lt; ticketArray.length() ; i++){
                                  ViewTicketModel ticket_object = new ViewTicketModel();
                                  JSONObject ticketVal = ticketArray.getJSONObject(i);
                                  String diagnosa = ticketVal.getString("first");
                                  String noPasien = ticketVal.getString("second");
                                  String dokter = ticketVal.getString("3rd");
                                  String jenisPerawatan = ticketVal.getString("4th");
  
                                  ticket_object.setJenis_perawatan(jenisPerawatan);
                                  ticket_object.setNomor_pasien(noPasien);
                                  ticket_object.setDoctor(dokter);
  
                                  ticket_list_mdl.add(ticket_object);
                                  adapter.notifyDataSetChanged();
                                  // stopping swipe refresh
                                  swipeRefreshView.setRefreshing(false);
                              }
  
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
                      }
                  }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  Log.v("V_error",error.toString());
                  // stopping swipe refresh
  //                swipeRefreshView.setRefreshing(false);
              }
          }) {
              @Override
              protected Map&lt;String, String&gt; getParams() {
                  Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
                  params.put("a", token);
                  params.put("b", signature);
                  params.put("c", pvd_code);
                  return params;
              }
          };
  
          RequestQueue ticketQueue = Volley.newRequestQueue(ViewTickets.this);
          ticketQueue.add(getTicket);</code></pre>
  </div>
  </div>
  </p>
  
  <p>and here is my on refresh method</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@Override
      public void onRefresh() {
          ViewTicketModel ticketModel = new ViewTicketModel();
          String a = ticketModel.getmToken();
          String b = ticketModel.getmSignature();
          String c = ticketModel.getmPvdCode();
  
          getDataTicket(a,b,c);
      }</code></pre>
  </div>
  </div>
  </p>