title: AndroidStudio- Fatal error: IndexOutOfBoundsException: Invalid index 0, size is 0
body: <p>I was able to run my app successfully through the emulator. but suddenly a bunch of errors appeared so now I am not able to launch it. There is a Fatal error. Here is LogCat output:</p>
  
  <pre><code> 08-26 12:14:27.937    2112-2112/com.joudi.myapplication D/AndroidRuntime﹕ Shutting down VM
  08-26 12:14:27.938    2112-2112/com.joudi.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.joudi.myapplication, PID: 2112
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.joudi.myapplication/com.joudi.myapplication.MainActivity}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
              at android.app.ActivityThread.-wrap11(ActivityThread.java)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:148)
              at android.app.ActivityThread.main(ActivityThread.java:5417)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
       Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
              at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
              at java.util.ArrayList.get(ArrayList.java:308)
              at com.joudi.myapplication.MainActivity.onCreate(MainActivity.java:29)
              at android.app.Activity.performCreate(Activity.java:6237)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
              at android.app.ActivityThread.-wrap11(ActivityThread.java)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:148)
              at android.app.ActivityThread.main(ActivityThread.java:5417)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  </code></pre>
  
  <p>I do not know ow to fix the "IndexOutOfBoundsException: Invalid index 0, size is 0" error. Here is my MainActicity.java file code: </p>
  
  <pre><code>import android.graphics.Canvas;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.ListView;
  
  import com.joudi.myapplication.data.NoteItem;
  import com.joudi.myapplication.data.NotesDataSource;
  
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity {
  
      private NotesDataSource datasource;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          datasource = new NotesDataSource(this);
          List&lt;NoteItem&gt; notes= datasource.findAll();
          NoteItem note = notes.get(0);
          note.setText("Updated!");
          datasource.update(note);
  
          notes= datasource.findAll();
          note= notes.get(0);
  
          Log.i("NOTES", note.getKey());
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>