Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7924375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:43:15+00:00 2026-06-03T17:43:15+00:00

I’ve got an activity where a viewflipper shows a list containing the artists from

  • 0

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 turn displays the songs on that album. Once a song is clicked, it should populate a textview with the string ‘title’.

Until this point, all of the cursors are working fine, but the very last one seems to get put out of position somehow. Could anyone tell me why logcat is telling me:

05-07 23:58:54.195: E/AndroidRuntime(1961): java.lang.IllegalStateException: Couldn't read row 3, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.

The particular row which cannot be read varies depending on which artist/album/song is chosen. The code is as follows. Thank you very much for your help.

package music.flipper;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.provider.MediaStore.Audio.AlbumColumns;
import android.provider.MediaStore.Audio.ArtistColumns;
import android.provider.MediaStore.Audio.AudioColumns;
import android.provider.MediaStore.MediaColumns;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class MusicFlipper extends Activity implements OnItemClickListener {
    /** Called when the activity is first created. */

    ViewFlipper viewflipper;
    Cursor cursor;

    private String currentList = "Artist";
    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

        setContentView(R.layout.flipper);
        //set the main view to flipper.
        viewflipper = (ViewFlipper) findViewById(R.id.viewFlipper1);

        String[] columns = { 
                BaseColumns._ID,
                ArtistColumns.ARTIST 
                };
        //The columns to return for each row.   

        cursor = managedQuery(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
            columns, null, null, null);

        ListView listView = (ListView) findViewById(R.id.listView1);
        listView.setOnItemClickListener(this);

        //set an onitemclicklistener to the first listview in flipper

        String[] displayFields = new String[] { ArtistColumns.ARTIST };
        //set all the artist names to the array 'displayfields'
        int[] displayViews = new int[] { R.id.rowItem };
        //number of rows to display and where to bind them

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            R.layout.row_item, cursor, displayFields, displayViews);
        listView.setAdapter(adapter); }
        //Take the display fields array, and bind to the matching display row

     @SuppressWarnings("deprecation")

    public void onItemClick(AdapterView<?> a, View v, int position, long id) {

        if( currentList.equals("Artist")) {
            if (cursor.moveToPosition(position)) {
            //once an item is clicked, move the cursor to that items position

            String where = AudioColumns.ARTIST + "=?";
            // Have the cursor look within the artist row?

            String whereVal[] = { cursor.getString(cursor
          .getColumnIndex(AlbumColumns.ARTIST)) };
            //Choose the particular row with the chosen artist's name

            String[] columns = {
                    BaseColumns._ID,
                    AudioColumns.ALBUM,
               };

                String orderBy = BaseColumns._ID;

            cursor = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                columns, where, whereVal, orderBy);

            ListView listView = (ListView) findViewById(R.id.listView2);
            listView.setOnItemClickListener(this);
            String[] displayFields = new String[] { AudioColumns.ALBUM };
            int[] displayViews = new int[] { R.id.rowItem };
            SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                R.layout.row_item, cursor, displayFields, displayViews);
            listView.setAdapter(adapter);
            currentList = "Album";
            viewflipper.showNext();}

        } if (currentList.equals("Album")) {
            if (cursor.moveToPosition(position)) {

                String where = AudioColumns.ALBUM
                + "=?";

                String whereVal[] = { cursor.getString(cursor
                .getColumnIndex(AlbumColumns.ALBUM)) };

                String[] columns = {
                        MediaColumns.DATA,
                        BaseColumns._ID,
                        MediaColumns.TITLE,
                        MediaColumns.DISPLAY_NAME,
                        MediaColumns.MIME_TYPE,
                   };

                    String orderBy = MediaColumns.TITLE;

                cursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    columns, where, whereVal, orderBy);

                ListView listView = (ListView) findViewById(R.id.listView3);
                listView.setOnItemClickListener(this);
                String[] displayFields = new String[] { MediaColumns.TITLE };
                int[] displayViews = new int[] { R.id.rowItem };
                SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                    R.layout.row_item, cursor, displayFields, displayViews);
                listView.setAdapter(adapter);
                currentList.equals("Songs");
                viewflipper.showNext();}


        } if (currentList.equals("Songs")) {
            if (cursor.moveToPosition(position)) {

                String title = cursor.getString(cursor.getColumnIndex(MediaColumns.TITLE));

                TextView myTextView = (TextView) findViewById(R.id.title);
                myTextView.setText(title);

            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:43:16+00:00Added an answer on June 3, 2026 at 5:43 pm

    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);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.