Reputation: 11782
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);
Guys i am getting error , java.lang.IllegalArgumentException: the bind value at index 4 is null
Any help will be appreciated
Upvotes: 1
Views: 3749
Reputation: 6173
Most likely the: integerToDB(account.parentAccountId) returns null and then you set the value at index 4 to null:
(integerToDB(account.parentAccountId) != null ? integerToDB(account.parentAccountId).toString() : null)
Upvotes: 0
Reputation: 67286
This error comes when you are firing some query with where clause
or any other condition
with value as null
.
Example- select * from tbl_name where _id = null
where as it should be
select * from tbl_name where _id = some_id
So debug and check that when your query is fired you have all your values that are used in building your query.
In your case it seems that this line,
(integerToDB(account.parentAccountId) != null ?
integerToDB(account.parentAccountId).toString() : null)
is returning null
so check this value.
Upvotes: 3