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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:49:21+00:00 2026-05-26T12:49:21+00:00

I make a database with four columns. @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE

  • 0

I make a database with four columns.

  @Override
  public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE contacts (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT, type TEXT);");
  }

Now I have the _id of a particular row and I am trying to retrieve the column values(four column values) of that particular row. My code is as follows.

 public Cursor getById(String id) {

    String[] args = { id };
    return (getReadableDatabase().rawQuery("SELECT _id, name, email, type FROM contacts WHERE _id=?", args));
 }

 Cursor c = getById(row_id);
 String name = c.getString(1);

Its fiving the following exception.

Uncaught handler: thread main exiting due to uncaught exception
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
at com.app.friendlist.FriendList$2.onItemClick(FriendList.java:109)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3285)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)

Please help and suggest where the problem is. Thanks.

  • 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-26T12:49:21+00:00Added an answer on May 26, 2026 at 12:49 pm

    You need to use it like this –

     Cursor c = getById(row_id);
     if(c.getCount()>0)
     {
         c.moveToFirst();
         String name = c.getString(1);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make custom select from the database table using Linq. We use
How to make database connection pool in PowerBuilder (v9+) with... ...ODBC? ...SQL Server? ...Oracle?
How can we make one database restore date to date, like sunday to wednesday
I need to make a database that is highly localized. For almost all entities
My boss asks me to write only ANSI SQL to make it database independent.
I have a Linux web server and I'd like to make some database tables
In a SQL-database I make some selects, that get an duration (as result of
I have to make a decision of which database server to use for my
I would like to make a First Access Database Setup Process in my spring
I want to make a code snippet database web application. Would the best way

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.