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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:40:44+00:00 2026-05-18T00:40:44+00:00

I tried to load a list of values from a table, but the cursor

  • 0

I tried to load a list of values from a table, but the cursor doesn’t find the columns?
The Code which is buggy:

public final AccessToken[] fetchAccessTokenByServerId(final long serverId) {
    final Cursor c = db.query(
            ACCESS_TOKEN_TABLE,
            new String[] { ACCESS_TOKEN_COL_ID, ACCESS_TOKEN_COL_VALUE },
            ACCESS_TOKEN_COL_SERVER_ID + "=?",
            new String[] { Long.toString(serverId) },
            null,
            null,
            null);

    AccessToken[] result = new AccessToken[c.getCount()];
    for (int i = 0; i < result.length; i++) {
        long id = c.getLong(c.getColumnIndexOrThrow(ACCESS_TOKEN_COL_ID));
        String value = c.getString(c.getColumnIndexOrThrow(ACCESS_TOKEN_COL_VALUE));

        result[i] = new AccessToken(value, id, serverId);
        c.moveToNext();
    }
    return result;
}

public static final String COL_ID = "_id";
public static final String ACCESS_TOKEN_TABLE = "accesstoken";
public static final String ACCESS_TOKEN_COL_ID = COL_ID;
public static final String ACCESS_TOKEN_COL_SERVER_ID = "server_id";
public static final String ACCESS_TOKEN_COL_VALUE = "value";

But the first two statements in the for-loop fails:

Index -1 is requested, with a size of
1

The table exists with the columns: _id (= int), server_id (= int) and value (= string)

There is one entry: 1, 1, test

The parameter of the function is 1.

Sincerely
xZise

  • 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-18T00:40:45+00:00Added an answer on May 18, 2026 at 12:40 am

    Just after initializing your cursor, do this:

    c.moveToFirst();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to load a list of objects from XML using
I have a list of constant values which are stored in a database table.
i tried to find how i could load kml file and I found that
Here's my setup. public class ItemList : List<Item> { public void Load() {...} public
I'm trying to load data from a .txt file with PHP, but I fail
I show dialog of checkboxes (list retrieved from DB) to allow user select, which
I need to pre-load some values from a php script, I'm using a $.post
We need to store a list of data we pull from another table that
i have tried load and hebrew didn't work for me so i changed my
I've tried to load Disqus with ajax in my page, i'll explain. I have

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.