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 7048915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:56:57+00:00 2026-05-28T02:56:57+00:00

I’m attempting to create an app to pull the sqlite data from a preexisting

  • 0

I’m attempting to create an app to pull the sqlite data from a preexisting database, one copied to a directory before the app is run. The database contains upwards of 2000 rows and around 20 columns.

DBAdapter class.

package com.t3hh4xx0r.gmusicsniper;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBAdapter {

    public static final String KEY_ROWID = "Id";
    public static final String KEY_TITLE = "Title";
    private static final String DATABASE_NAME = Constants.gMusicSniperDir + Constants.musicDB;
    private static final String DATABASE_TABLE = "MUSIC";

    private static final int DATABASE_VERSION = 37;


    private final Context context; 

    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;

    public DBAdapter(Context ctx) {
        this.context = ctx;
        DBHelper = new DatabaseHelper(context);
    }

    private static class DatabaseHelper extends SQLiteOpenHelper {
        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
            // TODO Auto-generated method stub

        }
    }

    //---opens the database---
    public DBAdapter open() throws SQLException {
        db = SQLiteDatabase.openDatabase(DATABASE_NAME, null, SQLiteDatabase.OPEN_READONLY);
        return this;
    }

    //---closes the database---    
    public void close() {
        DBHelper.close();
    }

    //---retrieves a particular title---
    public Cursor getTitle(int songFinalValue) throws SQLException {
        Cursor mCursor =
                db.rawQuery("SELECT Title FROM MUSIC WHERE Id = 5899;", null);
                //db.query(DATABASE_TABLE, new String [] {KEY_TITLE}, KEY_ROWID + " = \'" + songFinalValue + "\'", null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }

}

Method where data is -supposed- to be retrieved.
songFinalValue is in this test case 5899, though ive hardcoded the value into the query statement to be sure that the issue wasnt with any uninitialized variables.

songFinalValue refers to the first column, Id.
The value that Im trying to return is of the corresponding Title, column 13.

    private void getTrackName(String songFinal) {
        int songFinalValue = Integer.parseInt(songFinal);
        DBAdapter db = new DBAdapter(this);

        //---get a title---
        db.open();
        Cursor c = db.getTitle(songFinalValue);
        while (c.isAfterLast() == false && c != null) {
           c.getString(13); // will fetch you the data
           c.moveToNext();
            //DisplayTitle(c);
            String cS = String.valueOf(c);               
Log.d("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", cS);
            }
        db.close();
        }

When ran, it errors with

E/CursorWindow(17998): Failed to read row 0, column 13 from a CursorWindow which has 1 rows, 1 columns.
    E/su      (18033): sudb - Database closed
    W/System.err(17998): java.lang.IllegalStateException: Couldn't read row 0, col 13 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.

Ive been working on this for a while, and have visited every guide, tutorial, and have poured over many SOF questions, and I cant seem to figure out the issue.

This is my first foray into SQLite databases, and also one of my first apps. Im assuming the error is something easily solved by anyone with experience, it usually ends up being some stupid mistake on my part, though I cant for the life of me figure out what it would be.

  • 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-05-28T02:56:58+00:00Added an answer on May 28, 2026 at 2:56 am

    Answered in comments.

    Take a look at code – db.rawQuery(“SELECT Title FROM MUSIC WHERE Id = 5899;”, null); This will return single column if given ID matches. – AVD Dec 27 ’11 at 4:04

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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
Basically, what I'm trying to create is a page of div tags, each has
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I

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.