繁体   English   中英

在Objective-C中创建数据库时出错

[英]Error while creating db in objective-c

我正在使用cordova 2.1.0框架在IOS中创建一个应用程序。 我正在使用以下代码在Objective-C中创建sqlite3 db:

NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
self.databaseFile = [docDir stringByAppendingPathComponent:@"splistdb.sqlite3"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;


if (![fileManager fileExistsAtPath:self.databaseFile]) {
    /*[fileManager copyItemAtPath:[[NSBundle mainBundle] pathForResource:@"FriendsDatabase" ofType:@"sqlite3"] toPath:dbFileName error:&error];*/
    NSString *path = [[NSBundle mainBundle] pathForResource:@"splistdb" ofType:@"sqlite3"];
    NSLog(@"doc path=%@",path);
    [fileManager copyItemAtPath:path toPath:self.databaseFile error:&error];
    [self createConfigTable];
    NSLog(@"database created");
} else {
    NSLog(@"fail to create database");
}

我在构建阶段标题中包含了libsqlite3.dylib文件。 但是我得到以下错误:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager copyItemAtPath:toPath:error:]: source path is nil'

我的代码有什么问题? 谢谢。

您的错误消息说该pathnil ,可能是因为未将文件splistdb.sqlite3复制到应用程序捆绑包中。 确保它在您的项目中,并且已添加到目标应用程序中。

最有可能这行给你零价值

NSString *path = [[NSBundle mainBundle] pathForResource:@"splistdb" ofType:@"sqlite3"];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM