iPhone应用程序将EXC_BAD_ACCESS与文件内容中的字典一起投掷

时间:2010-04-26 23:45:28

标签: iphone dictionary crash exc-bad-access nsmutabledictionary

我有代码

 NSArray *paths = [[NSArray alloc]   
initWithArray:NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)]; 

NSString *docsDirectory = [[NSString alloc] initWithString:[paths objectAtIndex:0]];

NSLog(@"This app's documents directory: %@",docsDirectory);

NSString *docsDirectoryWithPlist = [[NSString alloc] initWithFormat:@"%@/Stuff.plist", docsDirectory];



BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:docsDirectoryWithPlist isDirectory:NO];

if (fileExists) 
{
    chdir([docsDirectory UTF8String]);
    NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"Stuff.plist"];

在应用程序的applicationDidFinishLaunching方法中,无论何时到达最后一行,它都会崩溃,并在此过程中抛出EXC_BAD_ACCESS

提前致谢!

1 个答案:

答案 0 :(得分:3)

NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"Stuff.plist"];

此行尝试从bundle目录中读取文件。从完整路径读取文件:

NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:docsDirectoryWithPlist];