title: Android : IndexOutOfBoundsException: Invalid index 8, size is 0
body: <p>I have an error ,and i'm seeking it since yesterday .It seems to be a broblem of size in an array.
  This is the function when the exception seems to happen :</p>
  
  <pre><code>     private XYMultipleSeriesDataset getTruitonBarDataset() {
          XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
  
          int [] classObject  =new int[] {-70,-56,-45,-80,-47,-55,-80,-50,-75,-85,-35,-45};//Signal strength receiver from each access point
  
          for (int j=0;j&lt;classObject.length;j++){
          values.add(new int[] { classObject[j]}); //every serie will concern an access point and contain one RSSI
          }
  
          final int nr = classObject.length;
          ArrayList&lt;String&gt; legendTitles = new ArrayList&lt;String&gt;();
          for (int k = 0; k &lt; classObject.length; k++) {
               legendTitles.add("Sales"+k);//every serie will have a legend
          }
          SERIES_NR = classObject.length ;//number of access point
        for (int i = 0; i &lt; SERIES_NR; i++) {//Loop for every series
              CategorySeries series = new CategorySeries(legendTitles.get(i));
              int[] v = values.get(i);
              int seriesLength = v.length;
              dataset.addSeries(series.toXYSeries());
  
                         for (int k = 0; k &lt; seriesLength; k++) {
                   Log.i("STOOP SERIES_NR",SERIES_NR+"");
                   Log.i("STOOP ii",i+"");
                   Log.i("STOOP",k+"");
                   Log.i("STOOP",v[k]+"");
                   Log.i("STOOP",v[k] / 10+"");
                  /* XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 40 - v[k] %10);*/
  
                  switch (v[k] / 10){
                  case -8 :
                      //series.add(classObject[k]);
                      if (v[k] %10 == 0)
                          //series.add(40);
                      {XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 40);
                      }
                      else 
                      //series.add(40 - v[k] %10);
                      {XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 40 - v[k] %10);
                      }   
  
                      break;
                  case -7 :
                      //series.add(classObject[k]);
                      if (v[k] %10 == 0)
                          {
                          XYSeries tempSerie = dataset.getSeriesAt(i);
                        tempSerie.add(i, 50);
                          tempSerie.addAnnotation("text *** "+i, 0, 50);
  
                          }
  
                      else // EDITED 
                      //series.add(50 - v[k] %10);
                          {XYSeries tempSerie = dataset.getSeriesAt(i);
                          // ERROR LINE 100 tempSerie.add(i, 7.5,50 - v[k] %10);
  
  
   tempSerie.add(i,50 - v[k] %10);//right line 
                  //  series.toXYSeries().add(7.5,50 - v[k] %10);
                          }
  
                      break;
                  case -6 :
                      //series.add(classObject[k]);
                      if (v[k] %10 == 0)
                          //series.add(60);
                      {XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 60);
  
                      }
                      else
                      //series.add(60 - v[k] %10);
                      {XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 60 - v[k] %10);
  
                      }
  
                      break;
  
                  case -5 :
                      //series.add(classObject[k]);
                      if (v[k] %10 == 0)
                          //series.add(70);
                      {XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 70);
  
                      }
                      else
                      //series.add(70 - v[k] %10);
                      {XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 70 - v[k] %10);
  
                      }
  
                      break;
                  case -4 :
                      //series.add(classObject[k]);
                      if (v[k] %10 == 0)
                          //series.add(80);
                      {XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 80);
  
                      }
  
                      else
                      {XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 80 - v[k] %10);
                      tempSerie.addAnnotation("text"+i, i, 80 - v[k] %10);
  
                      }
  
  
                      break;
                  case -3 :
                      //series.add(classObject[k]);
                      if (v[k] %10 == 0)
                      {XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 90);
  
                      }
                      else
                      //series.add(90 - v[k] %10);
                      {XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 90 - v[k] %10);
  
                      }
  
                      break;
  
  
                  }
  
  
             }
  
  
  
          }
          return dataset;
      }
  </code></pre>
  
  <p>When i delete the switch condition part, and put this code, i don't get any exception :</p>
  
  <pre><code>XYSeries tempSerie = dataset.getSeriesAt(i);
                      tempSerie.add(i, 40 - v[k] %10);
  </code></pre>
  
  <p>.I tryed to run the code mannualy ,and i did not found an error (maybe i don't see it ).
  Here the running stops (Log.i )</p>
  
  <pre><code>04-11 08:58:24.415: I/STOOP(17738): -47
  04-11 08:58:24.415: I/STOOP(17738): -4
  04-11 08:58:24.415: I/STOOP SERIES_NR(17738): 12
  04-11 08:58:24.415: I/STOOP ii(17738): 5
  04-11 08:58:24.415: I/STOOP(17738): 0
  04-11 08:58:24.415: I/STOOP(17738): -55
  04-11 08:58:24.415: I/STOOP(17738): -5
  04-11 08:58:24.416: I/STOOP SERIES_NR(17738): 12
  04-11 08:58:24.416: I/STOOP ii(17738): 6
  04-11 08:58:24.416: I/STOOP(17738): 0
  04-11 08:58:24.416: I/STOOP(17738): -80
  04-11 08:58:24.416: I/STOOP(17738): -8
  04-11 08:58:24.416: I/STOOP SERIES_NR(17738): 12
  04-11 08:58:24.416: I/STOOP ii(17738): 7
  04-11 08:58:24.416: I/STOOP(17738): 0
  04-11 08:58:24.416: I/STOOP(17738): -50
  04-11 08:58:24.416: I/STOOP(17738): -5
  04-11 08:58:24.416: I/STOOP SERIES_NR(17738): 12
  04-11 08:58:24.416: I/STOOP ii(17738): 8
  04-11 08:58:24.416: I/STOOP(17738): 0
  04-11 08:58:24.416: I/STOOP(17738): -75
  04-11 08:58:24.417: I/STOOP(17738): -7
  </code></pre>
  
  <p><strong>And this is the exception that i'm having :</strong></p>
  
  <pre><code>    04-11 08:58:24.431: W/dalvikvm(17738): threadid=1: thread exiting with uncaught exception (group=0x419559a8)
  04-11 08:58:24.439: E/AndroidRuntime(17738): FATAL EXCEPTION: main
  04-11 08:58:24.439: E/AndroidRuntime(17738): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.truitonachartengine/com.example.truitonachartengine.TruitonAChartEngineActivity}: java.lang.IndexOutOfBoundsException: Invalid index 8, size is 0
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at android.app.ActivityThread.access$600(ActivityThread.java:162)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at android.os.Handler.dispatchMessage(Handler.java:107)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at android.os.Looper.loop(Looper.java:194)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at android.app.ActivityThread.main(ActivityThread.java:5371)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at java.lang.reflect.Method.invoke(Method.java:525)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at dalvik.system.NativeStart.main(Native Method)
  04-11 08:58:24.439: E/AndroidRuntime(17738): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 8, size is 0
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at java.util.ArrayList.add(ArrayList.java:143)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at org.achartengine.util.IndexXYMap.put(IndexXYMap.java:42)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at org.achartengine.model.XYSeries.add(XYSeries.java:155)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at com.example.truitonachartengine.TruitonAChartEngineActivity.getTruitonBarDataset(TruitonAChartEngineActivity.java:100)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at com.example.truitonachartengine.TruitonAChartEngineActivity.onCreate(TruitonAChartEngineActivity.java:37)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at android.app.Activity.performCreate(Activity.java:5122)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
  04-11 08:58:24.439: E/AndroidRuntime(17738):    ... 11 more
  </code></pre>
  
  <p>I'll appreciate any help .Thank you.</p>