title: index out of bound exeception when call one item in arraylist
body: <p>I want to get one item in array list but it give me error java.lang.IndexOutOfBoundsException: Invalid index 1, size is 0
  i call this listEvent.get(1).getTotal() where listEvent is my arraylist
  how can i retrieve an element from arraylist?</p>
  
  <p>here is my code</p>
  
  <pre><code> private void getData() {
          //Adding the method to the queue by calling the method getDataFromServer
  
          requestQueue.add(getDataFromServer(requestCount));
          //Incrementing the request counter
  
          if(requestCount &lt;= **listEvent.get(1).getTotal()**) {
              requestCount++;
          }
      }
  </code></pre>
  
  <p>here is my full code</p>
  
  <pre><code>import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.widget.SwipeRefreshLayout;
  import android.support.v7.widget.DefaultItemAnimator;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.view.GestureDetector;
  import android.view.LayoutInflater;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ProgressBar;
  import android.widget.Toast;
  
  import com.anakacara.anakacara.App.AppConfig;
  import com.anakacara.anakacara.App.Event;
  import com.anakacara.anakacara.Helper.CardAdapter;
  import com.anakacara.anakacara.R;
  import com.anakacara.anakacara.activity.DetailEvent;
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.JsonArrayRequest;
  import com.android.volley.toolbox.Volley;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * A simple {@link Fragment} subclass.
   * Activities that contain this fragment must implement the
   * {@link EventFragment.OnFragmentInteractionListener} interface
   * to handle interaction events.
   * Use the {@link EventFragment#newInstance} factory method to
   * create an instance of this fragment.
   */
  public class EventFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
      // TODO: Rename parameter arguments, choose names that match
      // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
      private static final String ARG_PARAM1 = "param1";
      private static final String ARG_PARAM2 = "param2";
  
      // TODO: Rename and change types of parameters
      private String mParam1;
      private String mParam2;
  
      //Creating a List of event
      private List&lt;Event&gt; listEvent;
  
      //Creating Views
      private RecyclerView recyclerView;
      private RecyclerView.LayoutManager layoutManager;
      private RecyclerView.Adapter adapter;
      private int requestCount = 1;
      private OnFragmentInteractionListener mListener;
      private RequestQueue requestQueue;
      private ProgressBar progressBar;
      private SwipeRefreshLayout swipeRefreshLayout;
      public EventFragment() {
          // Required empty public constructor
      }
  
      /**
       * Use this factory method to create a new instance of
       * this fragment using the provided parameters.
       *
       * @param param1 Parameter 1.
       * @param param2 Parameter 2.
       * @return A new instance of fragment EventFragment.
       */
      // TODO: Rename and change types and number of parameters
      public static EventFragment newInstance(String param1, String param2) {
          EventFragment fragment = new EventFragment();
          Bundle args = new Bundle();
          args.putString(ARG_PARAM1, param1);
          args.putString(ARG_PARAM2, param2);
          fragment.setArguments(args);
          return fragment;
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (getArguments() != null) {
              mParam1 = getArguments().getString(ARG_PARAM1);
              mParam2 = getArguments().getString(ARG_PARAM2);
          }
      }
  
      private final RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(final RecyclerView recyclerView, final int newState) {
              // code
              if (isLastItemDisplaying(recyclerView)) {
                  //Calling the method getdata again
                  getData();
              }
          }
  
          @Override
          public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
              // code
              if (isLastItemDisplaying(recyclerView)) {
                  //Calling the method getdata again
                  getData();
              }
          }
      };
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View x =  inflater.inflate(R.layout.fragment_event,null);;
          progressBar = (ProgressBar) x.findViewById(R.id.progressBar1);
          recyclerView = (RecyclerView) x.findViewById(R.id.recyclerView);
          recyclerView.setHasFixedSize(true);
          layoutManager = new LinearLayoutManager(getActivity());
          recyclerView.setLayoutManager(layoutManager);
          swipeRefreshLayout = (SwipeRefreshLayout) x.findViewById(R.id.swipeRefreshLayout);
          swipeRefreshLayout.setOnRefreshListener(this);
  
          /**
           * Showing Swipe Refresh animation on activity create
           * As animation won't start on onCreate, post runnable is used
           */
          swipeRefreshLayout.post(new Runnable() {
                                      @Override
                                      public void run() {
                                          swipeRefreshLayout.setRefreshing(true);
  
                                          getData();
                                      }
                                  }
          );
  
  
  
  
          //Initializing our event list
          listEvent = new ArrayList&lt;&gt;();
          requestQueue = Volley.newRequestQueue(getActivity());
          //Calling method to get data
          getData();
  
  //        swipeRefreshLayout= (SwipeRefreshLayout) x.findViewById(R.id.swipeRefreshLayout);
  //        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
  //        {
  //            @Override
  //            public void onRefresh()
  //            {
  //                if (isLastItemDisplaying(recyclerView)) {
  ////Calling the method getdata again
  //                    getData();
  //                    progressBar.setVisibility(View.GONE);
  //                }
  //            }
  //        });
          recyclerView.addOnScrollListener(rVOnScrollListener);
          adapter = new CardAdapter(listEvent, getActivity());
  
          //Adding adapter to recyclerview
          recyclerView.setAdapter(adapter);
          RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator();
          itemAnimator.setAddDuration(1000);
          itemAnimator.setRemoveDuration(1000);
          recyclerView.setItemAnimator(itemAnimator);
          recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), recyclerView, new ClickListener() {
              @Override
              public void onClick(View view, int position) {
                  Intent intent = new Intent(getActivity(), DetailEvent.class);
                  intent.putExtra("event_judul", listEvent.get(position).getJudul()); //you can name the keys whatever you like
                  intent.putExtra("event_deskripsi", listEvent.get(position).getDeskripsi()); //note that all these values have to be primitive
  </code></pre>
  
  <p>here is my json code </p>
  
  <pre><code>0:  {
  "id": 5
  "judul": "asdfasdfasdf"
  "deskripsi": "asfasdfasdfqwer"
  "duit": 123123
  "persen": 65
  "sisahari": 43
  "gambar": "http://192.168.0.13/task_manager/image/not4.jpeg"
  "total": 4
  }-
  1:  {
  "id": 4
  "judul": "asdfasfasdfas"
  "deskripsi": "dafasdfasdfasdfasfdasdf"
  "duit": 12341234
  "persen": 12
  "sisahari": 31
  "gambar": "http://192.168.0.13/task_manager/image/not3.jpeg"
  "total": 4
  }
  </code></pre>
  
  <p>i need access total but because in array 0 and 1 it is same i just need to access one of them
  i want to using code like this 
              if(requestCount &lt;= 4) {
                  requestCount++;
              }
  which is 4 is page limit, but i want to get it from array so it will be dynamic instead of manual like this</p>