我在此行中收到此异常“绑定或列索引超出范围”:
Cursor cursor = db.query(TABLE_NAME, null, ID, new String[] { id }, null, null, null);
我想检查给定的 id 是否存在于数据库中,但查询总是抛出这个异常,我不知道出了什么问题。我试过这个,但它是一样的例外:
Cursor cursor = db.query(TABLE_NAME, null, ID+" = ?", new String[] { id }, null, null, null);
这是我编写的方法。如果这里有什么问题,请告诉我:
public boolean existsAcc(String id)
{
//Check the parameters
if (id == null)
{
throw new IllegalArgumentException(
"The id parameter cannot be null");
}
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, null, ID, new String[] { id }, null, null, null);
if (!cursor.moveToFirst())
{
cursor.close();
return false;
}
cursor.close();
return true;
}