2011-05-27 27 views
2

我有一个处理数据库操作的对象。它开始与:奇数NSString行为“警告:无法读取符号...”

-(id)init{ 
    databaseName = @"WhoPaidLast.sql"; 

    // I think this one gets it from the app whereas the next one gets it from the phone 
    // databasePath = [[NSBundle mainBundle] pathForResource:@"WhoPaidLast" ofType:@"sql"]; 

    // Get the path to the documents directory and append the databaseName 
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDir = [documentPaths objectAtIndex:0]; 
    self.databasePath = [documentsDir stringByAppendingPathComponent:databaseName]; 

    // Execute the "checkAndCreateDatabase" function 
    [self checkAndCreateDatabase]; 

    return self; 

在本月底我检查DB:

-(void) checkAndCreateDatabase{ 
    // Check if the SQL database has already been saved to the users phone, if not then copy it over 
    BOOL success; 

    // Create a FileManager object, we will use this to check the status 
    // of the database and to copy it over if required 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 

    // Check if the database has already been created in the users filesystem 
    success = [fileManager fileExistsAtPath:self.databasePath]; 

    // If the database already exists then return without doing anything 
    if(success) return; 

    // If not then proceed to copy the database from the application to the users filesystem 

    // Get the path to the database in the application package 
    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; 

    // Copy the database from the package to the users filesystem 
    [fileManager copyItemAtPath:databasePathFromApp toPath:self.databasePath error:nil]; 

    //[fileManager release]; 
} 

在此之后,当我去使用databasePath我只似乎能够它抛出之前使用一次这个错误:

warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.1 (8G4)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found). 

我有一个从数据库返回一堆值的函数。第一次使用detabasePath时,它工作正常并输出预期值,第二次抛出上述错误。

这里是函数的开头:

// Setup the database object 
    sqlite3 *database; 

    // Init groupsArray 
    groupsArray = [[NSMutableArray alloc] init]; 


    NSLog(@"r- %@",self.databasePath); 
    NSLog(@"s- %@",self.databasePath); 
    // Open the database from the users filessytem 
    if(sqlite3_open([self.databasePath UTF8String], &database) == SQLITE_OK) { 

如果我删除第二个NSLog的函数,那么错误被用于下一次databasePath。如果我删除它,它将为sqlite3_open函数工作,但在下次使用时出错。

如果有人知道我错误的来源和/或我可能做错了什么,我非常感谢你的帮助。

谢谢。

回答

0

看起来上面的代码中存在一些与内存管理相关的错误。我猜测你看到的调试器错误是由于调试器不能锁存到给你一个堆栈跟踪的内存相关崩溃。

首先,你的-init方法永远不会在超类上调用它,这是不对的。你需要有类似

if (!(self = [super init])) 
{ 
    return nil; 
} 

在该方法的开始。

这样一来就会导致各种有趣的崩溃。除此之外,请确保databasePath属性设置为使用copyretain(最好是copy,因为它是NSString),或者它不会保留由[documentsDir stringByAppendingPathComponent:databaseName]返回的自动释放对象。

另外,我知道你已经注释掉了,但不要使用[fileManager release]。这是你从[NSFileManager defaultManager]得到的共享实例,但你没有保留它,所以释放会导致不好的事情。

你可以尝试启用断点并打开NSZombie来找到你的具体的崩溃位置,但我敢打赌,原因是我上面列出的因素之一。

0

这是式IO/Xcode中的4

中的错误

终端
cd /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.1\ \(8G4\)/Symbols/ 

sudo ln -s /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/Developer/ Developer 

清洁(移+ CMD + k)的项目之前运行它输入以下2个命令。问题应该解决。

Ref:http://blog.damore.it/2011/04/xcode4-debugging-problem-warning-unable.html

相关问题