title: ERROR java.lang.ArrayIndexOutOfBoundsException: length=5; index=5
body: <p>I'm working on <em>Android Studio Project</em> for my university (app calendar and more), and one of the functionalities is touch in a day of a calendar (<code>CalendarView</code>), display a layout for add event and later the event is saved in a <code>SQLITE</code>, (in another activity is where the list of events is displayed) the problem is when I want to delete an event (<code>java.lang.ArrayIndexOutOfBoundsException: length=5; index=5</code>).
  In Viewevents eliminar(<code>String dato</code>) is the code with error, How do I fix the issue? Thanks.</p>
  
  <p>View events:</p>
  
  <pre><code>public class ViewEventsActivity extends AppCompatActivity implements AdapterView.OnItemLongClickListener {
  //al mantener la wea apretada
  private SQLiteDatabase db;
  private ListView listView;
  private ArrayAdapter&lt;String&gt; arrayAdapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_view_events);
  
      listView=(ListView) findViewById(R.id.ltvListaEventos);
      listView.setOnItemLongClickListener(this);
  
      Bundle bundle= getIntent().getExtras();
      int dia,mes,anio;
      dia=mes=anio=0;
  
      dia=bundle.getInt("dia");
      mes=bundle.getInt("mes");
      anio=bundle.getInt("anio");
      String cadena= dia+" - "+ mes + " - "+ anio;
  
      BDSQLite bd= new BDSQLite(getApplicationContext(), "eventos", null,1);
      db= bd.getReadableDatabase();
  
      String sql="select * from eventos where fechadesde='"+cadena+"'";
      Cursor c;
  
  
  
      String nombre,fechadesde,horadesde,fechahasta,horahasta,descripcion,ubicacion;
      try {
          c=db.rawQuery(sql,null);
          arrayAdapter= new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1);
          if(c==null||c.getCount()==0) {
              Toast.makeText(getBaseContext(), "No hay eventos disponibles", Toast.LENGTH_LONG).show();
          }
  
  
  
  
          if(c.moveToFirst()){
              do {
                  nombre=c.getString(1);
                  ubicacion=c.getString(2);
                  fechadesde=c.getString(3);
                  horadesde=c.getString(4);
                  fechahasta=c.getString(5);
                  horahasta=c.getString(6);
                  descripcion=c.getString(7);
                  arrayAdapter.add(nombre+", "+ubicacion+", "+fechadesde+", "+horadesde+", "+fechahasta+", "+horahasta+", "+descripcion);
              } while(c.moveToNext());
              listView.setAdapter(arrayAdapter);
          }
  
      }catch (Exception ex) {
          Toast.makeText(getApplication(), "Error: "+ex.getMessage(), Toast.LENGTH_SHORT).show();
          this.finish();
  
      }
  
  
  }
  
  
  
  private  void  eliminar(String dato){
      String []datos= dato.split(", ");
  
      String sql="delete from eventos where nombreEvento='"+datos[0]+"' and" +
              " ubicacion='"+datos[1]+"' and fechadesde='"+datos[2]+"' and " +
              "horadesde='"+datos[3]+"' and fechahasta='"+datos[4]+"' and horahasta='"+datos[5]+"' and descripcion='"+datos[6];
      try {
  
          arrayAdapter.remove(dato);         //eliminar del menú
          listView.setAdapter(arrayAdapter);
          db.execSQL(sql);
  
  
          Toast.makeText(getApplication(),"Evento eliminado",Toast.LENGTH_SHORT).show();
      }catch (Exception ex){
          Toast.makeText(getApplication(),"Error:"+ ex.getMessage(), Toast.LENGTH_SHORT).show();
      }
  
  }
  
  @Override
  public boolean onItemLongClick(final AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
      AlertDialog.Builder builder= new AlertDialog.Builder(this);
      CharSequence []items= new CharSequence[2];
      items[0]="Eliminar Evento";
      items[1]="Cancelar";
      builder.setTitle("Eliminar evento")
              .setItems(items, new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int i) {
                      if(i==0){
                          //eliminar evento
                          eliminar(adapterView.getItemAtPosition(i).toString());
                      }
                  }
              });
  
      AlertDialog dialog= builder.create();
      dialog.show();
      return false;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>BDSQlite:</p>
  
  <pre><code>public class BDSQLite extends SQLiteOpenHelper {
  
  private String sql = "create table eventos(" +
          "idEvento int identity,"+
          "nombreEvento varchar(40)," +
          "ubicacion varchar(60)," +
          "fechadesde date,"+
          "horadesde time,"+
          "fechahasta date,"+
          "horahasta time," +
          "descripcion varchar(60))";
  </code></pre>
  
  <p>Add event activity</p>
  
  <pre><code>public class AddActivity extends AppCompatActivity implements View.OnClickListener {
  
  
  private EditText nombreEvento, ubicacion, fechadesde, horadesde, fechahasta, horahasta;
  private EditText descripcion;
  
  private Button guardar, cancelar;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_add);
  
      nombreEvento = (EditText) findViewById(R.id.edtNombreEvento);
      ubicacion = (EditText) findViewById(R.id.edtUbicacion);
      fechadesde = (EditText) findViewById(R.id.edtFechaDesde);
      fechahasta = (EditText) findViewById(R.id.edtFechaHasta);
      horadesde = (EditText) findViewById(R.id.edtHorainicio);
      horahasta = (EditText) findViewById(R.id.edtHoraHasta);
      descripcion = (EditText) findViewById(R.id.edtDescripcion);
  
      Bundle bundle = getIntent().getExtras();
      int dia = 0, mes = 0, anio = 0;
  
      dia=bundle.getInt("dia");
      mes=bundle.getInt("mes");
      anio=bundle.getInt("anio");
  
  
      fechadesde.setText(dia + " - " + mes + " - " + anio);
      fechahasta.setText(dia + " - " + mes + " - " + anio);
  
      guardar = (Button) findViewById(R.id.btnguardar);
      cancelar = (Button) findViewById(R.id.btncancelar);
      guardar.setOnClickListener(this);
      cancelar.setOnClickListener(this);
  }
  
  @Override
  public void onClick(View v) {
      if (v.getId() == guardar.getId()) {
          //guardar datos cajas de texto
          BDSQLite bd = new BDSQLite(getApplication(), "eventos", null, 1);
          SQLiteDatabase db = bd.getWritableDatabase();
  
  
  
          String sql = "insert into eventos" +
                  "(nombreEvento, ubicacion, fechadesde, horadesde, fechahasta, horahasta," +
                  "descripcion) values('" +
                  nombreEvento.getText()+
                  "','"+ ubicacion.getText()+
                  "','" +fechadesde.getText()+
                  "','" + horadesde.getText()+
                  "','"+fechahasta.getText()+
                  "','"+horahasta.getText()+
                  "','"+descripcion.getText();
          try {
              db.execSQL(sql);
              nombreEvento.setText("");
              ubicacion.setText("");
              fechadesde.setText("");
              fechahasta.setText("");
              horadesde.setText("");
              horahasta.setText("");
              descripcion.setText("");
              Toast.makeText(getBaseContext(), "Evento guardado", Toast.LENGTH_LONG).show();
          } catch (Exception e) {
              Toast.makeText(getApplication(),"Error"+e.getMessage(),Toast.LENGTH_SHORT).show();
  
          }
  
      } else {
          this.finish();
          return;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>ERROR:</p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: length=5; index=5
  at com.example.niikoo.fondocelular.ViewEventsActivity.eliminar(ViewEventsActivity.java:87)
  at com.example.niikoo.fondocelular.ViewEventsActivity.access$000(ViewEventsActivity.java:17)
  at com.example.niikoo.fondocelular.ViewEventsActivity$1.onClick(ViewEventsActivity.java:116)
  </code></pre>
  
  <p>EDIT: The code with the structure of sql and datos, how i fix the error:(</p>