title: Android: java.lang.IndexOutOfBoundsException: Invalid index 9, size is 9
body: <p>I'm having a problem with my following code:</p>
  
  <pre><code>view.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick (View v) {
          int row = position +1;
          int listLength = data.size();
          HashMap&lt;String,String&gt; nextRow = data.get(position+1);
          if (row &lt; listLength ) {
              nextRow.put("greyedOut","false");
          } else {
              System.out.println("HATSIKIDEE!!");
          }
          notifyDataSetChanged();
          System.out.println(row);
          System.out.println(listLength);
      }
  });
  </code></pre>
  
  <p>This code is placed in my <code>Adapter</code> and adjusts the <code>ListView</code>, it works for every row but crashes when selecting the last row returning the following error: <code>java.lang.IndexOutOfBoundsException: Invalid index 9, size is 9</code></p>
  
  <p>What I don't understand is that the output of the System.out.println() is according to if statement:</p>
  
  <pre><code>    1 of 9
      2 of 9
      3 of 9
      4 of 9
      5 of 9
      6 of 9
      7 of 9
      8 of 9
  
  At 9 of 9 it crashes.
  Please help me how to solve this error.
  </code></pre>