title: How to fix the ArrayIndexOutOfBoundsException in Adapter android
body: <p>I'm using CardView, Json to load data and display in list item. But I build the first time, it happened an exception is: <code>ArrayIndexOutOfBoundsException</code> </p>
  
  <p>My Adapter class:</p>
  
  <pre><code>public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.ViewHolder&gt; {
  
  private static final int TYPE_HEADER = 4;
  private static final int TYPE_ITEM = 1;
  Context context;
  List&lt;CarData&gt; getCarData;  // getDataAdapter
  ImageLoader imageThumbLoader;
  
  public RecyclerViewAdapter(List&lt;CarData&gt; getCarData, Context context){
      super();
      this.getCarData = getCarData;
      this.context = context;
  }
  
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_items, parent, false);
      ViewHolder viewHolder = new ViewHolder(v);
      return viewHolder;
  }
  
  @Override
  public void onBindViewHolder(ViewHolder Viewholder, int position) {
  
          CarData getCarData1 = getCarData.get(position - 1);
  
          imageThumbLoader = ServerImageParseAdapter.getInstance(context).getImageLoader();
  
          imageThumbLoader.get(getCarData1.getImageThumb(),
                  ImageLoader.getImageListener(
                          Viewholder.imageThumb,//Server Image
                          R.mipmap.bg_icon,//Before loading server image the default showing image.
                          android.R.drawable.ic_dialog_alert //Error image if requested image dose not found on server.
                  )
          );
  
      Viewholder.imageThumb.setImageUrl(getCarData1.getImageThumb(), imageThumbLoader);
      Viewholder.titleName.setText(getCarData1.getTitleName());
      Viewholder.doorName.setText(Html.fromHtml("&lt;b&gt;Số cửa:&lt;/b&gt; " + getCarData1.getDoorName()));
      Viewholder.seatName.setText(Html.fromHtml("&lt;b&gt;Số ghế:&lt;/b&gt; " + getCarData1.getSeatName()));
      Viewholder.cityName.setText(Html.fromHtml(getCarData1.getCityName()));
      Viewholder.districtName.setText(Html.fromHtml(getCarData1.getDistrictName()));
  
  }
  
  public int getDataAdapter() {
      return getCarData == null ? 0 : getCarData.size();
  }
  
  @Override
  public int getItemViewType(int position) {
      if (isPositionHeader(position)) {
          return TYPE_HEADER;
      }
  
      return TYPE_ITEM;
  }
  
  @Override
  public int getItemCount() {
  
      return getDataAdapter() + 1;
  }
  
  private boolean isPositionHeader(int position) {
      return position == 0;
  }
  
  
  class ViewHolder extends RecyclerView.ViewHolder{
  
      public TextView titleName;
      public NetworkImageView imageThumb;
      public TextView doorName;
      public TextView seatName;
      public TextView cityName;
      public TextView districtName;
  
      public ViewHolder(View itemView) {
  
          super(itemView);
  
          titleName = (TextView) itemView.findViewById(R.id.titleName);
          imageThumb = (NetworkImageView) itemView.findViewById(R.id.imageThumb);
          doorName = (TextView) itemView.findViewById(R.id.doorName);
          seatName = (TextView) itemView.findViewById(R.id.seatName);
          cityName = (TextView) itemView.findViewById(R.id.cityName);
          districtName = (TextView) itemView.findViewById(R.id.districtName);
      }
    }
  }
  </code></pre>
  
  <p>and Logcat:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: pl.michalz.hideonscrollexample, PID: 3420
  java.lang.ArrayIndexOutOfBoundsException: length=18; index=-1
    at java.util.ArrayList.get(ArrayList.java:310)
    at pl.michalz.hideonscrollexample.RecyclerViewAdapter.onBindViewHolder(RecyclerViewAdapter.java:54)
    at pl.michalz.hideonscrollexample.RecyclerViewAdapter.onBindViewHolder(RecyclerViewAdapter.java:20)
    at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5768)
    at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5801)
  </code></pre>
  
  <p>How to fix this error, I have tried a lot of ways, but it seem not have result for.</p>