所以我试图从一个SQLite数据库的值到游标,然后选择一个随机值。我可以像getString()一样在该方法中读取游标,但是在它返回游标之后,它无法正常工作。我不知道为什么.. 这里是我从数据库获取游标的方法。它似乎工作正常。Android光标问题
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();
我可能犯了一个愚蠢的错误,没有意识到它,但我无法弄清楚这一点。
感谢,
〜Elec0
你不能在你要返回的光标上调用close(),然后使用它。删除该行,并在完成后关闭一次。 – LeffelMania 2011-03-23 18:32:15