title: How can i fix java.lang.IndexOutOfBoundsException: Invalid index in ArrayList on Android
body: <p>In my application I want get some <strong>list</strong> from server, and show this list into <strong><code>ChipCloud</code></strong>. <code>ChipCloud</code> has <strong>Tag</strong> library. <strong>Library Link :</strong> <a href="https://github.com/adroitandroid/ChipCloud" rel="nofollow noreferrer">https://github.com/adroitandroid/ChipCloud</a><br>
  .I write below code but when run application when click on items show me below <strong>error</strong> : </p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Invalid index 11, size is 6
  at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
  at java.util.ArrayList.get(ArrayList.java:308)
  at com.example.com.Activities.FullSearchMini$2$5.chipSelected(FullSearchMini.java:286)
  at com.adroitandroid.chipcloud.ChipCloud.chipSelected(ChipCloud.java:253)
  at com.adroitandroid.chipcloud.Chip.onClick(Chip.java:138)
  at android.view.View.performClick(View.java:4764)
  at android.view.View$PerformClick.run(View.java:19844)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5349)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
  </code></pre>
  
  <p><strong>My Codes :</strong> </p>
  
  <pre><code>public class FullSearchMini extends AppCompatActivity {
  
  @BindView(R.id.miniFullSearch_toolbarText)
  EditText fullSearchMini_headerText;
  @BindView(R.id.fullSearchMini_celebritiesRecyclerView)
  RecyclerView fullSearchMini_celebritiesRecyclerView;
  @BindView(R.id.miniFullSearch_movieRecyclerView)
  RecyclerView miniFullSearch_movieRecyclerView;
  @BindView(R.id.miniFullSearch_SeriesRecyclerView)
  RecyclerView miniFullSearch_SeriesRecyclerView;
  @BindView(R.id.miniFullSearch_UserRecyclerView)
  RecyclerView miniFullSearch_UserRecyclerView;
  @BindViews({R.id.fullSearchMini_celebritiesHeaderLay, R.id.miniFullSearch_movieHeaderLay, R.id.miniFullSearch_SeriesHeaderLay,
          R.id.miniFullSearch_UserHeaderLay})
  List&lt;RelativeLayout&gt; miniSearchLayouts;
  @BindViews({R.id.celebritiesLine, R.id.moviesLine, R.id.SeriesLine})
  List&lt;RelativeLayout&gt; miniSearchLines;
  @BindView(R.id.fullSearchMini_didYouMeanLay)
  RelativeLayout fullSearchMini_didYouMeanLay;
  @BindView(R.id.miniFullSearch_LoadLay)
  RelativeLayout miniFullSearch_LoadLay;
  @BindView(R.id.fullSearchMini_chipCloud)
  ChipCloud fullSearchMini_chipCloud;
  @BindView(R.id.fullSearchMini_EmptyLay)
  RelativeLayout fullSearchMini_EmptyLay;
  @BindView(R.id.empty_text)
  TextView empty_text;
  @BindView(R.id.miniFullSearch_LoadProgress)
  ProgressBar miniFullSearch_LoadProgress;
  private Context context;
  private MiniSearchCelebritiesAdapter celebritiesAdapter;
  private MiniSearchMoviesAdapter moviesAdapter;
  private MiniSearchSeriesAdapter seriesAdapter;
  private MiniSearchUsersAdapter userAdapter;
  private List&lt;Celebrity&gt; celebritiesModel = new ArrayList&lt;&gt;();
  private List&lt;Movie&gt; moviesModel = new ArrayList&lt;&gt;();
  private List&lt;Series&gt; seriesModel = new ArrayList&lt;&gt;();
  private List&lt;User&gt; userModel = new ArrayList&lt;&gt;();
  private String searchKey, chipKey;
  private List&lt;String&gt; cloudChipList = new ArrayList&lt;&gt;();
  private String[] mostlyMatchedKeywordsStrings;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_mini_full_search);
  
      // Initialize
      ButterKnife.bind(this);
      context = this;
  
      //Set Color to progressBar
      miniFullSearch_LoadProgress.getIndeterminateDrawable().setColorFilter(Color.parseColor("#ff8d00"),
              android.graphics.PorterDuff.Mode.SRC_ATOP);
  
      celebritiesAdapter = new MiniSearchCelebritiesAdapter(context, celebritiesModel);
      moviesAdapter = new MiniSearchMoviesAdapter(context, moviesModel);
      seriesAdapter = new MiniSearchSeriesAdapter(context, seriesModel);
      userAdapter = new MiniSearchUsersAdapter(context, userModel);
  
      initRecyclerView(fullSearchMini_celebritiesRecyclerView);
      initRecyclerView(miniFullSearch_movieRecyclerView);
      initRecyclerView(miniFullSearch_SeriesRecyclerView);
      initRecyclerView(miniFullSearch_SeriesRecyclerView);
      initRecyclerView(miniFullSearch_UserRecyclerView);
  
      // TextWatcher
      fullSearchMini_headerText.addTextChangedListener(new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  
          }
  
          @Override
          public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  
          }
  
          @Override
          public void afterTextChanged(Editable editable) {
              searchKey = editable.toString();
              if (searchKey.length() &gt; 1) {
                  getData(searchKey);
              }
          }
      });
  }
  
  private void getData(String key) {
      FullSearchSendData sendData = new FullSearchSendData();
      sendData.setKey(key);
      sendData.setLoadImages(true);
      sendData.setSearchInCelebrities(true);
      sendData.setSearchInMovies(true);
      sendData.setSearchInSeries(true);
      sendData.setSearchInEpisodes(false);
      sendData.setSearchInUsers(true);
      sendData.setPageIndex(1);
      sendData.setPageSize(4);
      sendData.setMaxDistance(1);
  
      miniFullSearch_LoadLay.setVisibility(View.VISIBLE);
  
      InterfaceApi api = ApiClient.getClient().create(InterfaceApi.class);
      Call&lt;FullSearchResponse&gt; call = api.getFullSearch(sendData);
  
      call.enqueue(new Callback&lt;FullSearchResponse&gt;() {
          @Override
          public void onResponse(Call&lt;FullSearchResponse&gt; call, Response&lt;FullSearchResponse&gt; response) {
              FullSearchResponse searchResponse = response.body();
              if (searchResponse.getData().getCelebrities() != null) {
                  if (searchResponse.getData().getCelebritiesCount() &gt; 0) {
                      celebritiesModel.clear();
                      celebritiesModel.addAll(searchResponse.getData().getCelebrities());
                      celebritiesAdapter.notifyDataSetChanged();
                      fullSearchMini_celebritiesRecyclerView.setAdapter(celebritiesAdapter);
                      miniSearchLayouts.get(0).setVisibility(View.VISIBLE);
                      miniSearchLines.get(0).setVisibility(View.VISIBLE);
                      fullSearchMini_celebritiesRecyclerView.setVisibility(View.VISIBLE);
  
                      miniSearchLayouts.get(0).setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              Intent intent = new Intent(context, FullSearch.class);
                              intent.putExtra(ExtraContains.FULL_SEARCH_TEXT.name(), searchKey);
                              startActivity(intent);
                          }
                      });
                  } else {
                      miniSearchLayouts.get(0).setVisibility(View.GONE);
                      miniSearchLines.get(0).setVisibility(View.GONE);
                      fullSearchMini_celebritiesRecyclerView.setVisibility(View.GONE);
                  }
              }
              if (searchResponse.getData().getMovies() != null) {
                  if (searchResponse.getData().getMoviesCount() &gt; 0) {
                      moviesModel.clear();
                      moviesModel.addAll(searchResponse.getData().getMovies());
                      moviesAdapter.notifyDataSetChanged();
                      miniFullSearch_movieRecyclerView.setAdapter(moviesAdapter);
                      miniSearchLayouts.get(1).setVisibility(View.VISIBLE);
                      miniSearchLines.get(1).setVisibility(View.VISIBLE);
                      miniFullSearch_movieRecyclerView.setVisibility(View.VISIBLE);
  
                      miniSearchLayouts.get(1).setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              Intent intent = new Intent(context, FullSearch.class);
                              intent.putExtra(ExtraContains.FULL_SEARCH_TEXT.name(), searchKey);
                              startActivity(intent);
                          }
                      });
                  } else {
                      miniSearchLayouts.get(1).setVisibility(View.GONE);
                      miniSearchLines.get(1).setVisibility(View.GONE);
                      miniFullSearch_movieRecyclerView.setVisibility(View.GONE);
                  }
              }
              if (searchResponse.getData().getSeries() != null) {
                  if (searchResponse.getData().getSeriesCount() &gt; 0) {
                      seriesModel.clear();
                      seriesModel.addAll(searchResponse.getData().getSeries());
                      seriesAdapter.notifyDataSetChanged();
                      miniFullSearch_SeriesRecyclerView.setAdapter(seriesAdapter);
                      miniSearchLayouts.get(2).setVisibility(View.VISIBLE);
                      miniSearchLines.get(2).setVisibility(View.VISIBLE);
                      miniFullSearch_SeriesRecyclerView.setVisibility(View.VISIBLE);
  
                      miniSearchLayouts.get(2).setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              Intent intent = new Intent(context, FullSearch.class);
                              intent.putExtra(ExtraContains.FULL_SEARCH_TEXT.name(), searchKey);
                              startActivity(intent);
                          }
                      });
                  } else {
                      miniSearchLayouts.get(2).setVisibility(View.GONE);
                      miniSearchLines.get(2).setVisibility(View.GONE);
                      miniFullSearch_SeriesRecyclerView.setVisibility(View.GONE);
                  }
              }
              if (searchResponse.getData().getUsers() != null) {
                  if (searchResponse.getData().getUsersCount() &gt; 0) {
                      userModel.clear();
                      userModel.addAll(searchResponse.getData().getUsers());
                      userAdapter.notifyDataSetChanged();
                      miniFullSearch_UserRecyclerView.setAdapter(userAdapter);
                      miniSearchLayouts.get(3).setVisibility(View.VISIBLE);
                      miniFullSearch_UserRecyclerView.setVisibility(View.VISIBLE);
  
                      miniSearchLayouts.get(3).setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              Intent intent = new Intent(context, FullSearch.class);
                              intent.putExtra(ExtraContains.FULL_SEARCH_TEXT.name(), searchKey);
                              startActivity(intent);
                          }
                      });
                  } else {
                      miniSearchLayouts.get(3).setVisibility(View.GONE);
                      miniFullSearch_UserRecyclerView.setVisibility(View.GONE);
                  }
              }
  
              // Did you mean
              String[] mostlyMatchedKeywordsStrings = searchResponse.getData().getMostlyMatchedKeywordsText();
              cloudChipList.clear();
              for (int i = 0; i &lt; mostlyMatchedKeywordsStrings.length; i++) {
                  cloudChipList.add(mostlyMatchedKeywordsStrings[i]);
                  if (i &gt;= mostlyMatchedKeywordsStrings.length - 2) {
                      fullSearchMini_didYouMeanLay.setVisibility(View.VISIBLE);
                      fullSearchMini_chipCloud.addChip(mostlyMatchedKeywordsStrings[i]);
  
                      Log.e("searchKeys", mostlyMatchedKeywordsStrings[i]);
                  }
              }
  
              fullSearchMini_chipCloud.setChipListener(new ChipListener() {
                  @Override
                  public void chipSelected(int i) {
                      chipKey = cloudChipList.get(i);
                      Intent intent = new Intent(context, FullSearch.class);
                      intent.putExtra(ExtraContains.FULL_SEARCH_TEXT.name(), chipKey);
                      startActivity(intent);
  
                  }
  
                  @Override
                  public void chipDeselected(int i) {
  
                  }
              });
  
              if (searchResponse.getData().getCelebrities().size() == 0 &amp;&amp; searchResponse.getData().getSeries().size() == 0
                      &amp;&amp; searchResponse.getData().getMovies().size() == 0 &amp;&amp; searchResponse.getData().getUsers().size() == 0) {
                  fullSearchMini_EmptyLay.setVisibility(View.VISIBLE);
                  empty_text.setText(context.getResources().getString(R.string.noResultFound) + " for : " + searchKey);
              } else {
                  fullSearchMini_EmptyLay.setVisibility(View.GONE);
              }
  
              miniFullSearch_LoadLay.setVisibility(View.GONE);
          }
  
          @Override
          public void onFailure(Call&lt;FullSearchResponse&gt; call, Throwable t) {
              miniFullSearch_LoadLay.setVisibility(View.GONE);
          }
      });
  }
  </code></pre>
  
  <p><strong>Show me above error for this line :</strong> </p>
  
  <pre><code>chipKey = cloudChipList.get(i);
  </code></pre>
  
  <p>How can I fix this error? Please help me my friend. I really need your help. please</p>