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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:54:00+00:00 2026-05-24T23:54:00+00:00

I am learning how to uses databases on Android and i am trying a

  • 0

I am learning how to uses databases on Android and i am trying a simple example in which i have two textboxes [brakes and rpm] when i enter values into those boxes and hit the “write button” it enters them into the database table “performance”. When i hit the “read” button it should query the table and print the contents but i get the following error while querying:

android.database.CursorIndexOutOfBoundsException: Index -1 re
quested, with a size of 0

Here is my relevant code:

private static final String KEY_ROWID = "_id";
private static final String KEY_BRAKES = "brakes";
private static final String KEY_RPM="rpm";
private static final String DATABASE_NAME = "MyDB2";
private static final String DATABASE_TABLE = "performance";
private static final int DATABASE_VERSION=1;
private static final String DATABASE_CREATE = "create table performance (_id integer primary key autoincrement, " + "brakes text not null, rpm text not null);";


    //--insert an entry to the database--
public void insertData(String filter, String data){
    ContentValues entry = new ContentValues();

    if(filter.equals("b")){
        entry.put(KEY_BRAKES, data);
        Log.d(TAG,"inserted brake data");
        db.insert(DATABASE_TABLE, null, entry);
    }
    else if (filter.equals("r")){
        entry.put(KEY_RPM, data);
        Log.d(TAG,"inserted rpm data");
        db.insert(DATABASE_TABLE, null, entry);
    }


}

    //--retrive all entries
public Cursor getAllData(){
    Log.d(TAG,"about to query");
    try{
    Cursor c = db.query(DATABASE_TABLE, new String[]{KEY_BRAKES,KEY_RPM}, null, null, null, null, null);
    Log.d(TAG,"id=" + c.getString(0));

    return c;
    }catch(Exception e){
        Log.d (TAG,"error");
        Log.e(TAG,e.toString());
    }

    return null;
}

And the way that i enter items is as follows:

brakeRead = brakes.getText().toString();
rpmRead = brakes.getText().toString();
db.open();
db.insertData("b", brakeRead);
db.insertData("r", rpmRead);
db.close();

And the way i query is as follows:

                db.open();
            Cursor c = db.getAllData();
            if(c.moveToFirst())
            {
                do{
                    output.append("id: " +  c.getString(0) + " brakes: " + c.getString(1) + " rpm: " + c.getString(2));
                }while(c.moveToNext());
            }
            db.close();

But i am getting this error while querying: android.database.CursorIndexOutOfBoundsException: Index -1 re
quested, with a size of 0

Can anyone see if i am doing something wrong?

  • 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-24T23:54:01+00:00Added an answer on May 24, 2026 at 11:54 pm

    Query is perfect to retieve data but you got error as listed below it means you have no record in your database, so i think there is something missing while inserting database

    android.database.CursorIndexOutOfBoundsException: Index -1 re quested, with a size of 0

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

Sidebar

Related Questions

I have written a simple database driven app in C# which uses a 2
I have a small RIA that I built as a learning/make-my-life-easier project that uses
I have been slowing learning and building my first android app. I'm VERY new
I've started learning Lisp recently and wanted to write a program which uses gtk
I am learning about jquery mobile. I came across a sample code which uses
I am learning .net and building a site that uses url routing. I have
I am currently learning MVVM abd the tutorial I have been using, simply uses
I have been learning HTML5. One of the examples I have encountered uses an
I have inherited a code-base that uses ASP.NET MVC 3. I'm learning it as
For learning and demonstrating, I need a macro which prints its parameter and evaluates

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.