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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:42:54+00:00 2026-06-04T17:42:54+00:00

Im trying to get the corresponding title to the given ID using the code

  • 0

Im trying to get the corresponding title to the given ID using the code below

public String get_Title(int id){
        Cursor c = db.query(true, DATABASE_TABLE, new String[] {
                APP_TITLE,
                },
                KEY_ROWID + "="  + id,
                null,
                null,
                null,
                null,
                null);

                String Final = c.getString(0);

                return Final;

        }

I keep gettting exceptions caused by the index out of bounds. IM not good with cursors, so if anyone could help me out here. :S

  • 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-04T17:42:56+00:00Added an answer on June 4, 2026 at 5:42 pm

    You must before String Final = c.getString(0) call c.moveToFirst() or c.moveToNext() and then it should works. Because Cursor is implicitly positioned to position before first row so you must at first move Cursor to first row and then you can get data from it.

    EDIT:


    So it should be like this:

    if (c.getCount()) { // if there is some data
       c.moveToFirst();
       String Final = c.getString(0);
    }
    else {
       Toast.makeText(YourActivityName.this, "No data found", Toast.LENGTH_SHORT).show();
    }
    

    So you wrote that you not good in work with Cursor little introduction:

    If you execute any statement, always instance of Cursor class will be
    returned. It’s version of a database cursor, it is used in many
    database systems.

    Class Cursor have following few basic methods:
    
    • getCount() – to get how many rows is in actual cursor
    • moveToFirst(), moveToNext() etc. – for moving between rows
    • getColumnNames() – to get column’ names
    • getColumnIndex() – to get the zero-based index for the given column
      name…
    • getString(), getInt() etc. – to get data of requested column’ index
    • requery() – once again execute cursor
    • close() – to release resources of cursor.
    • and next…

    More about work with cursors you find here

    Regards

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

Sidebar

Related Questions

I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
Im trying to get the index number of corresponding characters in a string. I
I'm trying to get the file corresponding to a given system font, e.g: In
I'm trying to get the corresponding /dev file given a path name, kind of
I'm trying to do the same as Get the key corresponding to the minimum
I am trying get Struts 2 and Tiles to work and I am using
Trying to get comfortable with jQuery and I have encountered some sample code that
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {

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.