gpt4 book ai didi

iphone - 从 sqlite 文件中选择数据中出现 NSInvalidArgumentException

转载 作者:行者123 更新时间:2023-12-03 19:41:37 24 4
gpt4 key购买 nike

我以以下格式存储数据

             05/03/2012 10:11PM : <0818aaaa aaaaaaaa aaaa454d 554c4154 4f520000 00000000 0000>

但是当检索数据时,我使用以下方法

    sqlite3 *database;

if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select logText from logTable";

sqlite3_stmt *compiledStatement;


if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {



while(sqlite3_step(compiledStatement) == SQLITE_ROW) {

NSString *addressField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(compiledStatement, 0)];

// Read the data from the result row

fullLog=[NSString stringWithFormat:@"%@%@",fullLog,addressField];

} // end of the while

}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);

我收到以下错误,

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithUTF8String:]: NULL cString'

* 第一次抛出时调用堆栈:

请帮助解释为什么会出现此问题

最佳答案

您无法使用 NULL 指针初始化 NSString 对象,因此只需检查该条件:

const char* addressField_tmp = (const char*)sqlite3_column_text(compiledStatement, 0);

NSString *addressField = addressField_tmp == NULL ? nil : [[NSString alloc] initWithUTF8String:addressField_tmp];

关于iphone - 从 sqlite 文件中选择数据中出现 NSInvalidArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10437086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com