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

  • Home
  • SEARCH
  • 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 9161447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:58:08+00:00 2026-06-17T13:58:08+00:00

I am trying to select certain rows from my database, but since I kept

  • 0

I am trying to select certain rows from my database, but since I kept getting index out of bound I decided to remove the WHERE part for now and just get all of the data.
I have used the android tutorial http://developer.android.com/training/basics/data-storage/databases.html#DbHelper , in order to create this method. But when I am trying to get values from the query I am getting CursorIndexOutOfBoundsException.

My Code:

String getSite() {
    SQLiteDatabase db = this.getReadableDatabase();
            //get all data for now
    Cursor c = db.query(
        TABLE_NAME,  // The table to query
        null,                               // The columns to return
        null,                                // The columns for the WHERE clause
        null,                            // The values for the WHERE clause
        null,                                     // don't group the rows
        null,                                     // don't filter by row groups
        null                                 // don't sort
        );
    c.moveToFirst();
        String test= c.getString(0); 
    c.close();
    return test;}
}

The Error:
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 6

when I checked for c.count() I got 6, so I am not sure why I am referring to an index that might out of bound

Thank you

  • 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-17T13:58:09+00:00Added an answer on June 17, 2026 at 1:58 pm

    Your cursor is empty if it didn’t move.

    try

    if (c.moveToFirst()) {
        String test= c.getString(0);
        // or String test= c.getString(c.getColumnIndex("column_name")); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select rows with a certain column name and order them by
I am trying to select rows which are within a certain time period: $sql
I'm trying to select rows where a certain column does not have a certain
I'm trying to investigate when & why certain rows are getting deleted in a
Ok, So I am trying to query my database and select all rows that
I am trying to extract duplicate rows from my database. I have a listings
I am trying to use css3's :not() selector to select certain elements that do
When trying to select fields from a subquery if ANY of the subqueries do
I am trying to select three values from xml document. I want to get
I am trying to select the last record from a table in MySQL using

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.