1

我正在尝试将对象添加到类 LyricsInfo 中的 ForeignCollection,但不幸的是我收到错误:“索引 1 处的绑定值为 null ”。有任何想法吗?我已经读过查询的selectionArg 参数可能会导致此异常。

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.<init>(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.<init>(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.<init>(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

歌词信息.java

public class LyricsInfo {
@DatabaseField(generatedId=true) @Getter @Setter private int id;
@ForeignCollectionField @Setter private ForeignCollection<Lyric> lyrics;
...

public List<Lyric> getLyrics() {
    ArrayList<Lyric> itemList = new ArrayList<Lyric>();
    CloseableWrappedIterable<Lyric> 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<String> 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(...);
    ...

}

}

歌词.java

@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;
    }
}
4

1 回答 1

0

如果您阅读以下两个答案中的任何一个:

他们似乎在说 Sqlite 正在引发异常,因为它试图迭代的字段之一是null. 有可能:

@DatabaseField(canBeNull=true) @NonNull @Getter @Setter private int time;

也许那应该是一个Integer?不过我只是猜测。如果您显示导致此问题的数据行,我们或许能够提供更具体的帮助。

于 2013-03-11T12:36:53.433 回答