java - 给出索引 4 处的绑定(bind)值为 null 的错误

标签 java android eclipse sqlite

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/

相关文章:

java - 我有 100 种使用 Java selenium Junit 进行测试的方法。如何在不使用@test注释的情况下编写方法

java - 将韩文(韩文字母)字母分解为各个元素?

java - 显示 java 文件上的 swt 选项卡

eclipse - GWT 安装目录的路径

java - 在 2 个 Activity 之间传递数据

java - 使用 Java 实现最小形状绘图工具桌面应用程序的指南

java - postgres 和 java 的内存缓存选项

android - 使用 NPR StreamProxy 实现时出现 MediaPlayer 错误

android - 在另一个 RecyclerView 中插入一个 RecyclerView

java.lang.OutOfMemoryError : PermGen space 错误