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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:38:31+00:00 2026-05-31T05:38:31+00:00

I’m trying to get the results from a Cursor and put them in into

  • 0

I’m trying to get the results from a Cursor and put them in into an Object that I created. In Eclipse, it appears the cursor is returning a single row (which is what I want) but when I try to access it, I get an error. Here’s the code to fetch a single row:

public Object fetchIssue(long IssueNumber, int type){

    //Get query cursor.
    Cursor cursor = mDB.query(true, ISSUES_TABLE, ISSUES_COLUMN_ARRAY, COL_ISSUE_ID + "=" + IssueNumber, null, null, null, null, null);

    int iCount = cursor.getCount();

    if(cursor == null)
        return null;

    Object objOut = null;

    if(type == QUERY_TYPE_STRING_ARRAY){
        //Create Array to hold Issue Information.
        String[] IssueInfo = new String[3];
        IssueInfo[0] = String.valueOf(IssueNumber);
        IssueInfo[1] = cursor.getString(cursor.getColumnIndexOrThrow(COL_DATE_RECEIVED));
        IssueInfo[2] = cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_SUMMARY));
        IssueInfo[3] = cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_STATUS));
        IssueInfo[4] = cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_SUB_STATUS));
        IssueInfo[5] = cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_DESCRIPTION));
        objOut = IssueInfo;
    }
    else{
        //Create IssueInfo object.
        IssueInfo IssueInfo = new IssueInfo(
                    IssueNumber, "12/12/2000",
                    //cursor.getString(cursor.getColumnIndexOrThrow(COL_DATE_RECEIVED)),
                    cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_SUMMARY)),
                    cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_STATUS)),
                    cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_SUB_STATUS)),
                    cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_DESCRIPTION)));
        objOut = IssueInfo;
    }

    //Close cursor.
    cursor.close();

    //Return IssueInfo.
    return objOut;
}

iCount returns 1 and if I put the cursor variable in the “variables” window, I can see all the columns:
Cursor variable

and at the top of the class, the table column variables are set to the same name:

public static final String ISSUES_TABLE = "Issues";
public static final String COL_ISSUE_ID = "_id";
public static final String COL_DATE_RECEIVED = "DateReceived";
public static final String COL_ISSUE_STATUS = "IssueStatus";
public static final String COL_ISSUE_SUB_STATUS = "IssueSubStatus";
public static final String COL_ISSUE_SUMMARY = "IssueSummary";
public static final String COL_ISSUE_DESCRIPTION = "IssueDescription";

private static final String[] ISSUES_COLUMN_ARRAY = new String[]{
    COL_ISSUE_ID, COL_DATE_RECEIVED, COL_ISSUE_SUMMARY, 
    COL_ISSUE_STATUS, COL_ISSUE_SUB_STATUS, COL_ISSUE_DESCRIPTION};

The error is occuring on this line:

//Create IssueInfo object.
        IssueInfo IssueInfo = new IssueInfo(
                    IssueNumber, "12/12/2000",
                    //cursor.getString(cursor.getColumnIndexOrThrow(COL_DATE_RECEIVED)),
                    cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_SUMMARY)),
                    cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_STATUS)),
                    cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_SUB_STATUS)),
                    cursor.getString(cursor.getColumnIndexOrThrow(COL_ISSUE_DESCRIPTION)));

or any of those lines (as you can see, I commented out the Date Received and put a normal string value in there, which it takes).

Here’s the error:

03-13 09:06:42.370: E/AndroidRuntime(2324): FATAL EXCEPTION: AsyncTask #2
    03-13 09:06:42.370: E/AndroidRuntime(2324): java.lang.RuntimeException: An error occured while executing doInBackground()
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at android.os.AsyncTask$3.done(AsyncTask.java:278)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at java.lang.Thread.run(Thread.java:856)
    03-13 09:06:42.370: E/AndroidRuntime(2324): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at android.database.AbstractCursor.checkPosition(AbstractCursor.java:400)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at com.adacel.dashboard.DBAdapter.fetchIssue(DBAdapter.java:215)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at com.adacel.dashboard.IssueInfoCreator.fetchIssue(IssueInfoCreator.java:42)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at com.adacel.dashboard.ViewIssue.LoadIssueDetails(ViewIssue.java:73)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at com.adacel.dashboard.ViewIssue.access$0(ViewIssue.java:70)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at com.adacel.dashboard.ViewIssue$GetIssueDetailsTask.doInBackground(ViewIssue.java:96)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at com.adacel.dashboard.ViewIssue$GetIssueDetailsTask.doInBackground(ViewIssue.java:1)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    03-13 09:06:42.370: E/AndroidRuntime(2324):     ... 4 more

Any help is greatly appreciated!

  • 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-31T05:38:33+00:00Added an answer on May 31, 2026 at 5:38 am

    Always move the Cursor to an element, after you query it:

    if(cursor == null)
        return null;
    if(!cursor.moveToFirst()) //this will move the cursor to the first element
        return null;
    

    if you expect multiple rows a better way to do it is:

    if(cursor != null) {
       cursor.move(-1);
       while(cursor.moveToNext()) {
          //do stuff
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.