title: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 onBindViewHolder
body: <p>Good afternoon everyone, I am facing this problem when creating my list in recyclerview.
  My API response has a list, and within that list is a list of Images, which I need to access to get the image link and upload it to my imageview.</p>
  
  <p><strong>My API Response:</strong></p>
  
  <pre><code>{
  "data": [
      {
          "id": "KCLSwV5",
          "title": "I wake up when i have my morning coffee",
          "description": null,
          "images": [
              {
                  "id": "k47zXXl",
                  "title": null,
                  "link": "https://i.imgur.com/k47zXXl.jpg"
              }
          ]
  
      }
      ]
  }
  </code></pre>
  
  <p>So I created my model this way.</p>
  
  <pre><code>public class Data implements Serializable {
  
  @SerializedName("id")
  @Expose
  private String id;
  
  @SerializedName("title")
  @Expose
  private String title;
  
  @SerializedName("description")
  @Expose
  private String description;
  
  @SerializedName("images")
  @Expose
  private List&lt;Images&gt; images = null;
  
  
  //Getters and Setters
  public List&lt;Images&gt; getImages() { return images; }
  
  public void setImages(List&lt;Images&gt; images) { this.images = images; }
  </code></pre>
  
  <p><strong>The error logs:</strong></p>
  
  <pre><code>    java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
      at java.util.ArrayList.get(ArrayList.java:437)
      at com.example.allan.galleryapp.adapter.ListAdapter.onBindViewHolder(ListAdapter.java:39)
      at com.example.allan.galleryapp.adapter.ListAdapter.onBindViewHolder(ListAdapter.java:18)
      at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
      at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
      at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
      at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
      at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
      at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
      at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
      at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:557)
      at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
      at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
      at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:171)
      at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
      at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3336)
      at android.view.View.measure(View.java:23187)
      at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
      at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
      at android.view.View.measure(View.java:23187)
      at android.support.v4.widget.SwipeRefreshLayout.onMeasure(SwipeRefreshLayout.java:641)
      at android.view.View.measure(View.java:23187)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6752)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
      at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
      at android.view.View.measure(View.java:23187)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6752)
      at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
      at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
      at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
      at android.view.View.measure(View.java:23187)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6752)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
      at android.view.View.measure(View.java:23187)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6752)
      at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
      at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
      at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
      at android.view.View.measure(View.java:23187)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6752)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
      at com.android.internal.policy.DecorView.onMeasure(DecorView.java:755)
      at android.view.View.measure(View.java:23187)
      at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2757)
      at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1606)
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1890)
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1494)
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7288)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
      at android.view.Choreographer.doCallbacks(Choreographer.java:761)
      at android.view.Choreographer.doFrame(Choreographer.java:696)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
  E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:873)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:193)
          at android.app.ActivityThread.main(ActivityThread.java:6923)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
  </code></pre>
  
  <p>logs say error is happening on my adapter in onBindViewHolder method.</p>
  
  <p><strong>My adapter:</strong></p>
  
  <pre><code>public class ListAdapter extends RecyclerView.Adapter&lt;ListAdapter.ListViewHolder&gt; {
  
  private Context context;
  private List&lt;Data&gt; dataList;
  
  public ListAdapter(Context context, List&lt;Data&gt; dataList) {
      this.context = context;
      this.dataList = dataList;
  }
  
  @NonNull
  @Override
  public ListAdapter.ListViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
      LayoutInflater inflater = LayoutInflater.from(context);
      View view = inflater.inflate(R.layout.list_item, viewGroup, false);
      return new ListAdapter.ListViewHolder(view);
  }
  
  @Override
  public void onBindViewHolder(@NonNull ListAdapter.ListViewHolder listViewHolder, int i) {
  
      String image = dataList.get(i).getImages().get(i).getLink(); //LINE 39 I believe the error is here, but I don't know how to solve it.
  
  
      Glide.with(context)
              .load(image)
              .apply(new RequestOptions()
              .placeholder(R.drawable.load))
              .into(listViewHolder.imageView);
  }
  
  @Override
  public int getItemCount() {
      return dataList.size();
  }
  
  public class ListViewHolder extends RecyclerView.ViewHolder {
      public ImageView imageView;
  
      public ListViewHolder(@NonNull View itemView) {
          super(itemView);
  
          imageView = itemView.findViewById(R.id.image);
      }
  }
  }
  </code></pre>
  
  <p>I will be grateful if anyone can help me.</p>
  
  <p>Cheers.</p>