Too many bind arguments. 5 arguments were provided but the statement needs 4 arguments

谁都会走 提交于 2019-12-22 04:11:09

问题


I get the IllegalArgumentException above when executing the function below. What I don't get is that when I run the debugger, the values variable clearly only contains 4 arguments, as it should.

So...

(1) Where does this mysterious fifth argument come from?

(2) How should I approach finding this error?

db.update(
    UppdragEntry.TABLE_NAME,
    values,
    selection,
    selectionArgs);

回答1:


Selection contains the following: String selection = "_id"; String[] selectionArgs = {" =" + personId};

You have a value in selectionArgs but no ? placeholder for it in selection.

Change it to

String selection = "_id = ?";
String[] selectionArgs = { "" + personId };

The method builds an SQL string. Supplied ContentValues are built as ? placeholder and bind arguments. Additional selection args are also provided as bind arguments and they must be matched with equal number of ? placeholders.



来源:https://stackoverflow.com/questions/24797635/too-many-bind-arguments-5-arguments-were-provided-but-the-statement-needs-4-arg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!