From cd935206e431f8aa125fc4403eecc26715bd2f0a Mon Sep 17 00:00:00 2001 From: Christopher Eby Date: Sun, 25 Sep 2011 04:01:46 -0500 Subject: [PATCH] Don't crash when failing to query a saved song --- src/org/kreed/vanilla/SongTimeline.java | 30 +++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/org/kreed/vanilla/SongTimeline.java b/src/org/kreed/vanilla/SongTimeline.java index 9e1b90d5..9ff0686c 100644 --- a/src/org/kreed/vanilla/SongTimeline.java +++ b/src/org/kreed/vanilla/SongTimeline.java @@ -220,21 +220,23 @@ public final class SongTimeline { Cursor cursor = resolver.query(media, Song.FILLED_PROJECTION, selection.toString(), null, "_id"); if (cursor != null) { - cursor.moveToNext(); + if (cursor.getCount() != 0) { + cursor.moveToNext(); - // Loop through timeline entries, looking for a row - // that matches the id. One row may match multiple - // entries. - Iterator it = songs.iterator(); - while (it.hasNext()) { - Song e = it.next(); - while (cursor.getLong(0) < e.id) - cursor.moveToNext(); - if (cursor.getLong(0) == e.id) - e.populate(cursor); - else - // We weren't able to query this song. - it.remove(); + // Loop through timeline entries, looking for a row + // that matches the id. One row may match multiple + // entries. + Iterator it = songs.iterator(); + while (it.hasNext()) { + Song e = it.next(); + while (cursor.getLong(0) < e.id && !cursor.isLast()) + cursor.moveToNext(); + if (cursor.getLong(0) == e.id) + e.populate(cursor); + else + // We weren't able to query this song. + it.remove(); + } } cursor.close();