title: Java Realm Out of Range Exception
body: <pre><code>Fatal Exception: java.lang.ArrayIndexOutOfBoundsException
  Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 108(requested: 0 valid: 0) io.realm.internal.OsResults.nativeGetRow
  
  MainActivity.randomizeEvents (MainActivity.java:1600)
  ...MainActivity$42.run (MainActivity.java:1739)
  </code></pre>
  
  <p><strong>randomizeEvents()</strong></p>
  
  <pre><code>public void randomizeEvents() {
      Realm nrealm;
      nrealm = Realm.getDefaultInstance();
      RealmResults&lt;Event&gt; eventList = nrealm.where(Event.class).equalTo("theevent", "theevent").findAll();
      if(eventList.size() != 0) {
          evt = eventList.get(0); &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;line 1600
          nrealm.beginTransaction();
          evt.setDurations();
          nrealm.commitTransaction();
      }
  
  }
  </code></pre>
  
  <p><strong>Method starting Runnable</strong></p>
  
  <pre><code>RealmResults&lt;Event&gt; eventList = realm.where(Event.class).equalTo("theevent", "theevent").findAll();
      evt = eventList.get(0);
  
      if(!eventTimerRunning) {
          runnable = new Runnable() {
              public void run() {
                  if(!realm.isClosed()) {
                      eventTimerRunning = true;
                      randomizeEvents(); &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;line 1739
                      handler.postDelayed(runnable, 30000);
                  }
              }
          };
          handler.postDelayed(runnable, 5000);
      }
  </code></pre>
  
  <p>I'm getting this error quite in different parts, but they are all doing the same thing. I have a <code>Runnable</code> for different things. For example this one will run that method every 30s after an initial delay. I am using a new instance of <code>Realm</code> in the <code>Runnable</code> due to errors from using one instance on UI thread and one on <code>runnable</code> etc. </p>
  
  <p>The <code>if</code> statement is <code>if(eventList.size() != 0)</code> so the size is 1+. Why would <code>eventList.size()</code> equal 1 or more, but still get the error about <code>eventList.get(0)</code> being null?</p>