I\'ve got an activity where a viewflipper shows a list containing the artists from mediastore, which onitem click display a list of albums by the chosen artist, which in tur
The problem isn't in the row, it's in the column.
Couldn't read row 3, **col -1** from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
It's basically saying that your MediaColumns.TITLE column doesn't exist in the cursor. Which is true. It's not in your first cursor (the one that it is referencing). Your other cursors are all within if
statements so go out of scope and leave only the first one.
You can either re-pull the cursor like you do in the other portions of the if
statement, or find some way to persist the cursor you got from the last if
statement.
EDIT
It's pretty simple to fix, make the cursor a class variable. Also, I wouldn't keep re-using "cursor". Label them somethign individual and descriptive, it'll help you maintain readability in your code. I might do it like this:
public class MusicFlipper extends Activity implements OnItemClickListener {
private Cursor artistCursor;
private Cursor albumCursor;
Then you call them like you were but use the individual names.
albumCursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
columns, where, whereVal, orderBy);
Since you declared it as a class variable it will be available through the whole class so in the last part you'd do:
if (currentList.equals("Songs")) {
if (albumCursor.moveToPosition(position)) {
String title = albumCursor.getString(albumCursor.getColumnIndex(MediaColumns.TITLE));
TextView myTextView = (TextView) findViewById(R.id.title);
myTextView.setText(title);
}
}