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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:46:03+00:00 2026-06-06T08:46:03+00:00

Hi all im using a sqlite helper class, but i have a little problem

  • 0

Hi all im using a sqlite helper class, but i have a little problem using a select statement.
I want to get the id of a datebase item by its name.

I use this select method:

public Cursor selectShift (String name){
    SQLiteDatabase db = dbHandler.getReadableDatabase();
    Cursor c = db.query(TABLE_NAME, null, "name=" + name, null, null, null, null);
    c.moveToFirst();
    db.close();
    return c;
}

And when i call this i use this:

if(handler.selectShift(name)!=null){
      Cursor c = handler.selectShift(name);
      id = c.getInt(c.getColumnIndex("_id"));
      c.close();      
  }

And then is get this error:

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

As if its not exists, but i checked the name string is correct, and when i display the names in a listview i see that name, so it exists.

Can someone help me how to fix this?

  • 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-06T08:46:06+00:00Added an answer on June 6, 2026 at 8:46 am

    Thanks for your help, i found the problem. It was in the cursor method, the solution is:

    public Cursor selectShift (String name){
        SQLiteDatabase db = dbHandler.getReadableDatabase();
        Cursor c = db.query(TABLE_NAME, new String[] {"_id"}, "name LIKE '"+name+"%'", null, null, null, null);
        c.moveToFirst();
        db.close();
        return c;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQLite in an Android application. In all of my tables I have
I've just started using SQLite and I want to write all my application data
I have some question regarding database performance in general. I'm using Sqlite but I
Using SQLite I need to copy nearly all of an existing row from a
We have a large number of programmers on different platforms all using CVS. We
Is okay to break all dependencies using interfaces just to make a class testable?
I am using sqlite in my android application. When i delete all the records
Using SQLite and Python 3.1, I want to display currency data in a HTML
I' m using sqlite on iphone. I have table with 200 000 records. It'
I have doing some POC in Ruby-on-Rails and using sqlite database, while doing 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.