绑定参数太多.提供了5个参数但声明需要4个参数

abc*_*112 9 java sqlite android sql-update

我在执行下面的函数时得到了IllegalArgumentException.我没有得到的是,当我运行调试器时,values变量显然只包含4个参数,因为它应该.

所以...

(1)这个神秘的第五个论点来自哪里?

(2)我应该如何找到这个错误?

db.update(
    UppdragEntry.TABLE_NAME,
    values,
    selection,
    selectionArgs);
Run Code Online (Sandbox Code Playgroud)

laa*_*lto 44

选择包含以下内容:String selection ="_ id"; String [] selectionArgs = {"="+ personId};

你有一个值,selectionArgs但没有?占位符selection.

将其更改为

String selection = "_id = ?";
String[] selectionArgs = { "" + personId };
Run Code Online (Sandbox Code Playgroud)

该方法构建一个SQL字符串.提供的ContentValues是构建为?占位符和绑定参数.其他选择参数也作为绑定参数提供,它们必须与相同数量的?占位符匹配.