我想实现下面的代码:String updateQuery ="INSERT INTO MAAccounts(userId, accountId, accountType, accountName, parentAccountId ) VALUES(?, ?, ?, ?, ?)";
Cursor c = mDb.rawQuery(updateQuery, new String[]{
stringToDB(account.userId),
integerToDB(account.accountId).toString(),
integerToDB(account.accountType.getValue()).toString(),
stringToDB(account.accountName),
integerToDB(account.parentAccountId).toString(),
});现在 parentAccoudId (Type int )的初始值是 null。实际上是把null转化为 to.String。当我运行它时,给出空指针的错误。我想在数据库中存储null值,如何实现?
2 回答

UYOU
TA贡献1878条经验 获得超4个赞
你可以使用android 提供的insert语句,使用
ContentValues values = new ContentValues();
values.put("key", Object);
的方式,你就不用关心Object是否为空的情况了,
或者你自己手动判断下Object是否为null,不等于null的情况在调用toString(),否则直接赋值null.
没有找到匹配的内容?试试慕课网站内搜索吧
添加回答
举报
0/150
提交
取消