String updateQuery ="INSERT INTO MAAccounts(userId, accountId, accountType, accountName, parentAccountId, currencyCode, isTransactionDefaultStatusOpen, currentBalance, monthlyBudget, createdOn, updatedOn) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
String[] valVars = {
stringToDB(account.userId),
integerToDB(account.accountId).toString(),
integerToDB(account.accountType.getValue()).toString(),
stringToDB(account.accountName),
(integerToDB(account.parentAccountId) != null ? integerToDB(account.parentAccountId).toString() : null),
stringToDB(account.currencyCode),
boolToDB(account.isTransactionDefaultStatusOpen).toString(),
CurrencyToDB(account.currentBalance).toString(),
CurrencyToDB(account.monthlyBudget).toString(),
dateToDB(now),
"false"};
Cursor c = mDb.rawQuery(updateQuery, valVars);
伙计们,我遇到了错误,java.lang.IllegalArgumentException:索引 4 处的绑定(bind)值为空
任何帮助将不胜感激
最佳答案
当您使用 where 子句
或 任何其他条件
并将值为 null
的查询触发时,会出现此错误。
示例- select * from tbl_name where _id = null
它应该在哪里
select * from tbl_name where _id = some_id
因此,调试并检查当您的查询被触发时,您是否拥有用于构建查询的所有值。
在你的情况下,这条线似乎是
(integerToDB(account.parentAccountId) != null ?
integerToDB(account.parentAccountId).toString() : null)
返回 null
所以检查这个值。
关于java - 给出索引 4 处的绑定(bind)值为 null 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9156528/