2009-09-11 27 views
0
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *myPlistPath = [documentsDirectory stringByAppendingPathComponent:@"Accounts.plist"]; 

NSArray *arr = [NSArray arrayWithContentsOfFile:myPlistPath]; 

int count = 0; 
for (NSDictionary *dict in arr) { 
     count += dict.count; 
} 

return count; 

我在做什么错?我在做什么错在我的代码?

上面的代码出现以下错误:程序收到信号:“EXC_BAD_ACCESS”。

+0

当你得到信号?在哪一行?你有没有在调试器中通过代码?我猜“路径”是空的。 – Justicle 2009-09-11 05:18:44

回答

3

EXC_BAD_ACCESS通常是内存故障,可能是由错误的地址引起的。

开始打印出pathsdocumentsDirectorymyPListPatharr(地址,而不是内容)设置后立即,看看其中是否已经被设置为NULL。

0

尝试打印myPListPath并验证它所指的文件实际上是否存在且格式正确。如果你问我,有机会,在这条线:

NSArray *arr = [NSArray arrayWithContentsOfFile:myPlistPath]; 

事情错了,并arr是越来越设置为null。