2009-09-11 38 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。