title: ORMLite the bind value at index 1 is null
body: <p>I am trying to add objects to the ForeignCollection in class LyricsInfo, but unfortunately I get the error: "<strong>the bind value at index 1 is null</strong>". Any ideas? I've already read that the <a href="https://stackoverflow.com/questions/4572090/android-sql-illegalargumentexception-the-bind-value-at-index-1-is-null">selectionArg argument</a> of a query can cause this exception.</p>
  
  <pre><code>03-10 14:07:35.545: W/System.err(26781): java.lang.IllegalStateException: Could not build lazy iterator for class com.ep45.db.Lyric
  03-10 14:07:35.545: W/System.err(26781):    at com.j256.ormlite.dao.LazyForeignCollection$1.closeableIterator(LazyForeignCollection.java:88)
  03-10 14:07:35.545: W/System.err(26781):    at com.j256.ormlite.dao.CloseableWrappedIterableImpl.closeableIterator(CloseableWrappedIterableImpl.java:32)
  03-10 14:07:35.545: W/System.err(26781):    at com.j256.ormlite.dao.CloseableWrappedIterableImpl.iterator(CloseableWrappedIterableImpl.java:22)
  03-10 14:07:35.545: W/System.err(26781):    at com.j256.ormlite.dao.CloseableWrappedIterableImpl.iterator(CloseableWrappedIterableImpl.java:12)
  03-10 14:07:35.545: W/System.err(26781):    at com.ep45.db.LyricsInfo.getLyrics(LyricsInfo.java:34)
  03-10 14:07:35.545: W/System.err(26781):    at com.ep45.db.LyricsInfo.&lt;init&gt;(LyricsInfo.java:82)
  03-10 14:07:35.545: W/System.err(26781):    at com.ep45.audio.AudioHelper.getSongInfo(AudioHelper.java:228)
  03-10 14:07:35.545: W/System.err(26781):    at com.ep45.activities.MainscreenActivity.loadNewSongs(MainscreenActivity.java:287)
  03-10 14:07:35.545: W/System.err(26781):    at com.ep45.activities.MainscreenActivity_.access$5(MainscreenActivity_.java:1)
  03-10 14:07:35.545: W/System.err(26781):    at com.ep45.activities.MainscreenActivity_$12.run(MainscreenActivity_.java:363)
  03-10 14:07:35.550: W/System.err(26781):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
  03-10 14:07:35.550: W/System.err(26781):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
  03-10 14:07:35.550: W/System.err(26781):    at java.lang.Thread.run(Thread.java:856)
  03-10 14:07:35.550: W/System.err(26781): Caused by: java.lang.IllegalArgumentException: the bind value at index 1 is null
  03-10 14:07:35.550: W/System.err(26781):    at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:297)
  03-10 14:07:35.550: W/System.err(26781):    at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:401)
  03-10 14:07:35.550: W/System.err(26781):    at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:55)
  03-10 14:07:35.555: W/System.err(26781):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
  03-10 14:07:35.555: W/System.err(26781):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1693)
  03-10 14:07:35.555: W/System.err(26781):    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1667)
  03-10 14:07:35.555: W/System.err(26781):    at com.j256.ormlite.android.AndroidCompiledStatement.getCursor(AndroidCompiledStatement.java:162)
  03-10 14:07:35.555: W/System.err(26781):    at com.j256.ormlite.android.AndroidCompiledStatement.runQuery(AndroidCompiledStatement.java:57)
  03-10 14:07:35.555: W/System.err(26781):    at com.j256.ormlite.stmt.SelectIterator.&lt;init&gt;(SelectIterator.java:55)
  03-10 14:07:35.555: W/System.err(26781):    at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java:232)
  03-10 14:07:35.555: W/System.err(26781):    at com.j256.ormlite.dao.BaseDaoImpl.createIterator(BaseDaoImpl.java:952)
  03-10 14:07:35.555: W/System.err(26781):    at com.j256.ormlite.dao.BaseDaoImpl.iterator(BaseDaoImpl.java:531)
  03-10 14:07:35.555: W/System.err(26781):    at com.j256.ormlite.dao.BaseDaoImpl.iterator(BaseDaoImpl.java:526)
  03-10 14:07:35.560: W/System.err(26781):    at com.j256.ormlite.dao.LazyForeignCollection.seperateIteratorThrow(LazyForeignCollection.java:75)
  03-10 14:07:35.565: W/System.err(26781):    at com.j256.ormlite.dao.LazyForeignCollection$1.closeableIterator(LazyForeignCollection.java:86)
  03-10 14:07:35.565: W/System.err(26781):    ... 12 more
  </code></pre>
  
  <p>LyricsInfo.java</p>
  
  <pre><code>public class LyricsInfo {
  @DatabaseField(generatedId=true) @Getter @Setter private int id;
  @ForeignCollectionField @Setter private ForeignCollection&lt;Lyric&gt; lyrics;
  ...
  
  public List&lt;Lyric&gt; getLyrics() {
      ArrayList&lt;Lyric&gt; itemList = new ArrayList&lt;Lyric&gt;();
      CloseableWrappedIterable&lt;Lyric&gt; it = lyrics.getWrappedIterable();
      try {
          for(Lyric lyric: it)
              itemList.add(lyric);
      } finally {
          try {
              it.close();
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
  
      return itemList;
  }
  
  public LyricsInfo(List&lt;String&gt; theLyrics) {
      try {
  
          if(lyrics == null)
              lyrics = DatabaseManager.getInstance().getHelper().getDao(DatabaseHelper.LYRICSINFO).getEmptyForeignCollection("lyrics");
      } catch (SQLException e) {
          Log.e("Test","Exception occured");
          e.printStackTrace();
      }
      ...
      lyrics.add(...);
      ...
  
  }
  
  }
  </code></pre>
  
  <p>Lyric.java</p>
  
  <pre><code>@DatabaseTable
  @RequiredArgsConstructor()
  @NoArgsConstructor()
  public class Lyric {
      @DatabaseField(generatedId=true) @Getter @Setter private int id;
      @DatabaseField(canBeNull=true) @NonNull @Getter @Setter private int time;
      @DatabaseField(canBeNull=true) @NonNull @Getter @Setter private String text;
      @DatabaseField(foreign=true,foreignAutoRefresh=true)  @Getter @Setter private LyricsInfo lyricsInfo;
  
  
      public void appendText(String text) {
          this.text += text;
      }
  }
  </code></pre>