我ContentValues
在程序中输入数据库时遇到了一些麻烦,事实证明这很难理解。我有一个ContentValues
对象,我添加了大约 50 个左右的条目,一切都很好,除了一个存储为“null”的条目。根据 LogCat 输出,我知道进入 的数据ContentValues
不为空。
相关代码:
if (database.isOpen() && !database.isReadOnly()) { //Check that the database is open and not read only
Log.d(TAG, "Entry string: " + data.getEntryString());
Log.d(TAG, "Key: " + Helper.COLUMN_ENTRY_STRING);
ContentValues values = new ContentValues(); //Create a new ContentValues object to store key value pairs for insertion
//Various values.put() calls...
values.put(Helper.COLUMN_ENTRY_STRING, data.getEntryString()); //Should put the String "Something"
Log.d(TAG, "Entry string from values: " + values.getAsString(Helper.COLUMN_ENTRY_STRING));
//Proceed with database insert here
}
LogCat 回应:
07-27 08:58:47.909: D/Handler(18020): Entry string: Something
07-27 08:58:47.909: D/Handler(18020): Key: Entry_String
07-27 08:58:47.909: D/Handler(18020): Entry string from values: null
我已经检查了几次代码,但我找不到任何解释。任何帮助将不胜感激。