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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:03:53+00:00 2026-05-18T09:03:53+00:00

I am an android novice and have been experimenting with SQLite and Android. I

  • 0

I am an android novice and have been experimenting with SQLite and Android. I am able to get queries and use the cursor results, but I can’t seem to get this the following code to work:

This is my Query statement, where queryWhere = “MyObject=”1″” and DATABASE_TABLE_TOQUERY = “FavoriteObjects”. These are all okay when viewed in an SQLite database viewer and it also returns a correct result if I execute the query using my SQLite database viewer.

public long findObject(String[] keys, String[] values,String DATABASE_TABLE_TOQUERY){
    try {
        if(keys.length<0 || keys.length!=values.length)
            System.exit(-1);
        String queryWhere = keys[0]+"=\""+values[0]+"\"";
        for(int i=1;i<keys.length;i++) {
            queryWhere+=" AND "+keys[i]+"=\""+values[i]+"\"";
        }
        Cursor mCursor = mDb.query(true, DATABASE_TABLE_TOQUERY, null, 
                    queryWhere, null, null, null, null, null);
        if (mCursor != null && mCursor.getCount()>0)
            return Long.parseLong(mCursor.getString(mCursor.getColumnIndex(KEY_ROWID)));

    }catch (SQLException e) {
        return -1;
    }
    return -1;
}

When I get the results after executing the query statement, Cursor mCursor has at least one row, but when I access that row using mCursor.getString(X), it throws a weird error:

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

If I check mCursor.getColumnIndex(KEY_ROWID), I get a 0 value (which is correct). Anyone have any suggestions?

Thanks!
Jon

  • 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-18T09:03:53+00:00Added an answer on May 18, 2026 at 9:03 am

    Try

    mCursor.moveToNext();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am novice in android development and facing some problems. I have installed Eclipse
Okay, first, I'm a noob at android programming. I have taken some Java, but
I am a novice with Java. I have to implement an array of objects
I notice that most android apps have some sort of standard in that they
I have an Android application in the market which connects and send POST and
I notice that (too) many applications on my Android phone require full internet access.
Android 2.3 was recently released last night. So naturally I tried my app on
I have a weird problem where I cannot run aapt from an sbt command
I parse XML data and put it into an object. This takes fairly long

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.