Add a check for an empty cursor in Song.randomize

This commit is contained in:
Christopher Eby committed 2010-05-24 15:45:58 -05:00
1 parent cea45b35e1
commit aa07a5264c
1 file changed
+2 -1
+2 -1
View File
@@ -171,7 +171,8 @@ public class Song implements Parcelable {
Cursor cursor = resolver.query(media, FILLED_PROJECTION, selection, null, null);
if (cursor != null) {
if (cursor.moveToPosition(ContextApplication.getRandom().nextInt(cursor.getCount()))) {
int count = cursor.getCount();
if (count > 0 && cursor.moveToPosition(ContextApplication.getRandom().nextInt(count))) {
populate(cursor);
flags |= FLAG_RANDOM;
}