gpt4 book ai didi

安卓光标问题

转载 作者:太空狗 更新时间:2023-10-29 15:49:13 24 4
gpt4 key购买 nike

所以我试图从 SQLite 数据库中获取值到游标中,然后选择一个随机值。我可以像通常在方法中那样使用 getString() 读取游标,但在它返回游标后它无法正常工作。我不知道为什么..这是我从数据库中获取游标的方法。它似乎工作正常。

        public Cursor getRandomText(String Rating)
{

Cursor cursor = myDatabase.query("Elec0RandTexts", new String[] {"Message"}, "Rating=?",
new String[]{Rating}, null, null, null);
cursor.moveToFirst();

cursor.close();

return cursor;

}

这是我在光标返回后读取光标的代码。

            Cursor result = dbh.getRandomText(Rating);
result.moveToFirst();

int RandText = rand.nextInt(result.getCount());

result.moveToPosition(RandText);
Toast.makeText(getApplicationContext(), "" + result.getString(RandText), Toast.LENGTH_LONG).show();

result.close();

我可能犯了一个愚蠢的错误并且没有意识到,但我想不通。

谢谢,

~电子0

最佳答案

cursor.close(); // in getRandomText()

之后您无法从游标获取任何数据 - 它已关闭。删除此行。

关于安卓光标问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5409864/

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