Cursor doesn't find columns?

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

Answers


Just after initializing your cursor, do this:

c.moveToFirst();

Need Your Help

C++ OpenGL flickering Issues

c++ opengl flicker

Im having a Problem, where when I just render 1 Cube it's all okay, but if I add multiple Cubes all of them start flickering.. might be because they are intefering each other but im using double du...