title: JSON Request returns null
body: <p>I am using Volley library on Android but when I make JSONArrayRequest, it automatically returns null. But if I keep debugging, in the second try it fills the array. Here are my codes:</p>
  
  <blockquote>
    <p>BackgroundTask.java</p>
  </blockquote>
  
  <pre><code>public class BackgroundTask{
  
      Context context;
      ArrayList&lt;Dua&gt; arrayList = new ArrayList&lt;&gt;();
      String json_url = "http://www.burakakyalcin.site/getDua.php";
  
      public BackgroundTask(Context context){
          this.context = context;
      }
  
      public ArrayList&lt;Dua&gt; getList(){
          JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.POST, json_url, (String)null, new Response.Listener&lt;JSONArray&gt;() {
              @Override
              public void onResponse(JSONArray response) {
                  int count = 0;
                  while(count&lt;response.length()){
                      try {
                          JSONObject jsonObject = response.getJSONObject(count);
                          Dua dua = new Dua(jsonObject.getString("DuaId"),jsonObject.getString("DuaSender"),jsonObject.getString("DuaHeader"),
                              jsonObject.getString("DuaText"),jsonObject.getString("DuaLike"));
                          arrayList.add(dua);
                          count++;
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                  }
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  Toast.makeText(context, error.toString(), Toast.LENGTH_LONG).show();
                  error.printStackTrace();
              }
          });
          MySingleton.getInstance(context).addToRequestQueue(jsonArrayRequest);
          return arrayList;
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>MyFragment.java</p>
  </blockquote>
  
  <pre><code>public class MyFragment extends Fragment{
  
      RecyclerView recyclerView;
      RecyclerView.Adapter adapter;
      RecyclerView.LayoutManager layoutManager;
      ArrayList&lt;Dua&gt; arrayList = new ArrayList&lt;&gt;();
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment_my, container, false);
          recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
          layoutManager = new LinearLayoutManager(getActivity().getApplicationContext());
          recyclerView.setHasFixedSize(true);
          BackgroundTask backgroundTask = new BackgroundTask(getActivity().getApplicationContext());
          arrayList = backgroundTask.getList();
          adapter = new RecyclerAdapter(arrayList);
          recyclerView.setAdapter(adapter);
          return rootView;
      }
  
  
  }
  </code></pre>
  
  <p>RecyclerAdapter.java</p>
  
  <pre><code>public class RecyclerAdapter extends RecyclerView.Adapter&lt;RecyclerAdapter.MyViewHolder&gt; {
  
  ArrayList&lt;Dua&gt; arrayList = new ArrayList&lt;&gt;();
  
  public RecyclerAdapter(ArrayList&lt;Dua&gt; arrayList){
      this.arrayList = arrayList;
  }
  
  
  public void setArrayList (ArrayList&lt;Dua&gt; arrayList){
      this.arrayList=arrayList;
      notifyItemRangeChanged(0, arrayList.size());
  }
  
  @Override
  public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_item, parent, false);
      MyViewHolder myViewHolder = new MyViewHolder(view);
      return myViewHolder;
  }
  
  @Override
  public void onBindViewHolder(MyViewHolder holder, int position) {
      holder.DuaSender.setText(arrayList.get(position).getDuaSender());
      holder.DuaHeader.setText(arrayList.get(position).getDuaHeader());
      holder.DuaLike.setText(arrayList.get(position).getDuaLike());
  }
  
  @Override
  public int getItemCount() {
      return arrayList.size();
  }
  
  public static class MyViewHolder extends RecyclerView.ViewHolder{
  
      TextView DuaHeader, DuaSender, DuaLike;
  
      public MyViewHolder(View itemView) {
          super(itemView);
          DuaHeader = (TextView) itemView.findViewById(R.id.duaHeaderRec);
          DuaSender = (TextView) itemView.findViewById(R.id.duaSenderRec);
          DuaLike = (TextView) itemView.findViewById(R.id.duaLikeRec);
      }
  }
  }
  </code></pre>