【问题标题】:Error while creating db in objective-c在objective-c中创建数据库时出错
【发布时间】:2013-04-12 06:18:19
【问题描述】:

我正在使用 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'

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

【问题讨论】:

    标签: ios objective-c cordova sqlite


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      这行很可能给你 nil 值

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

      【讨论】:

        猜你喜欢
        • 2017-01-28
        • 2015-04-12
        • 2016-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多