【问题标题】:Database connection, checking database path数据库连接,检查数据库路径
【发布时间】:2011-08-03 18:21:26
【问题描述】:

我已经在 sqlite manager 中创建了数据库。我的项目因异常而终止。当我得到断点的帮助时,我在第 3 行得到了“错误访问”。 我无法在第 3 行找到问题的解决方案。

-(void)checkAndCreateDB { 布尔成功; //NSFileManager 维护文件 NSFileManager *FileManager = [NSFileManager defaultManager]; //检查数据库路径 成功 = [FileManager fileExistsAtPath:dbpath]; //如果文件存在则返回true 如果(成功)返回; NSString *databasePathFromApp = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:dbname]; [FileManager copyItemAtPath:databasePathFromApp toPath:dbpath error:nil]; [文件管理器发布]; }

这里 dbpath=

/Users/gauravmurghai/Library/Application Support/iPhone Simulator/User/Applications/E48F72FD-5CC9-438C-B412-7D16FEF8DD8C/Documents/dbnitu.sqlite

错误显示在第 3 行:“EXC_BAD_ACCESS”。

第 3 行是:Success = [FileManager fileExistsAtPath:dbpath]; 我不明白问题出在哪里?无法克服这个错误。

【问题讨论】:

    标签: iphone


    【解决方案1】:
    -(void)checkAndCreateDB
    {
    
        //NSFileManager maintains file
        NSFileManager *FileManager = [NSFileManager defaultManager];
        //Checks Database Path
        if([FileManager fileExistsAtPath:dbpath]);
        //If file exists it return true
        return;
        NSString *databasePathFromApp = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:dbname];
    [FileManager copyItemAtPath:databasePathFromApp toPath:dbpath error:nil];
        [FileManager release];
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 2011-09-06
      相关资源
      最近更新 更多