我在将查询结果转换为整数时遇到了一些麻烦。我将查询的结果返回到游标中,并试图在另一个语句中再次使用该值。我知道正在返回的值是一个整数,但我似乎不能提取到一个整数变量的值。我也尝试将该语句返回给int,但这也不起作用。光标到整数转换
查询
public Cursor getCode(String name) throws SQLException
{
return db.rawQuery("select recipe_code from recipes where recipe_name = " + "'"+name+"'" ,null);
}
诠释转换工作现在
Cursor code = adapter.getCode(string);
code.moveToFirst();
int test = code.getInt(0);
调试时代码的价值是什么? – Lal
很多不同的字符,当我做了toString()它说'android.database.sql.SQLiteCursor @ cf5778c' – Hayes121
尝试如果'int i = code.getInt(0);'工作.. – Lal