gpt4 book ai didi

android - 光标找不到列?

转载 作者:行者123 更新时间:2023-11-29 15:32:56 24 4
gpt4 key购买 nike

我试图从表中加载值列表,但游标找不到列?有问题的代码:

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";

但是 for 循环中的前两个语句失败了:

Index -1 is requested, with a size of 1

该表包含以下列:_id (= int)、server_id (= int) 和 value (= string)

只有一个条目:1, 1, test

函数的参数为​​1。

真诚的徐子泽

最佳答案

在初始化你的游标之后,执行以下操作:

c.moveToFirst();

关于android - 光标找不到列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4118335/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com