Выдает ошибку, что значение привязки в индексе 4 является нулевым - PullRequest
1 голос
/ 06 февраля 2012
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: the bind value at index 4 is null

Любая помощь будет оценена

Ответы [ 2 ]

3 голосов
/ 06 февраля 2012

Эта ошибка возникает, когда вы запускаете какой-либо запрос с where clause или any other condition со значением как 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, поэтому проверьте это значение.

0 голосов
/ 06 февраля 2012

Скорее всего,: integerToDB (account.parentAccountId) возвращает значение NULL, а затем для индекса 4 устанавливается значение NULL:

(integerToDB(account.parentAccountId) != null ? integerToDB(account.parentAccountId).toString() : null)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...