title: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 - Database Reading - Android
body: <p>I created a method that reads data from a database and puts it in a <code>String</code> array.
  Android Studio doesn't give syntax errors but when i launch my app the log says:</p>
  
  <pre><code>03-19 16:31:20.938    2518-2518/com.mms.dailypill E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: com.mms.dailypill, PID: 2518
  java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
          at com.mms.dailypill.DBManager.getMedicines(DBManager.java:56)
  </code></pre>
  
  <p>The method code is:</p>
  
  <pre><code>public String[] getMedicines()
  {
      SQLiteDatabase db = dbManager.getWritableDatabase();
      String[] columns = {dbManager.getName(), dbManager.getFormat(), dbManager.getAmount(), dbManager.getExp_date(), dbManager.getTime()};
      Cursor cursor = db.query(dbManager.getTableName(), columns, null, null, null, null, null);
      String[] medicines = {};
  
      String name, format, exp_date, time;
  
      int amount;
      int count = 0;
      while(cursor.moveToNext())
      {
          name = cursor.getString(0);
          format = cursor.getString(1);
          amount = cursor.getInt(2);
          exp_date = cursor.getString(3);
          time = cursor.getString(4);
          medicines[count] = "Name: " + name + " Format: " + format + " Amount: " + amount + " Expiration Date: " + exp_date + " Time: " + time;
          count++;
      }
      db.close();
      return medicines;
  }
  </code></pre>
  
  <p>As the log says, the exception is given on the line 56:</p>
  
  <pre><code>time = cursor.getString(4);
  </code></pre>
  
  <p>The table i read has 6 columns: <code>id</code>, <code>name</code>, <code>format</code>, <code>amount</code>, <code>exp_date</code>, <code>time</code>. I only want to show the entire table without the <code>id</code> column, so when i call the <code>getString()</code> method i start from the index <code>1</code> and not from <code>0</code>.</p>
  
  <p>I really can't understand where the problem is, so if someone can help me i will appreciate it.
  Thanks in advance!</p>