Add a check for an empty cursor in Song.randomize

This commit is contained in:
Christopher Eby 2010-05-24 15:45:58 -05:00
parent cea45b35e1
commit aa07a5264c

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