2012-04-15 125 views
1

我是Xcode的新手。我想要的是在我的程序中讀取plist數據。我得到了 NSArrayM insertObject:atIndex:]: object cannot be nil錯誤。這是我聲明的和我的plist文件。感謝xcode NSArrayM insertObject:atIndex:]:object can not be nil

NSMutableArray *phoneArray; 

NSString *path=[[NSBundle mainBundle] pathForResource:@"PhoneList" ofType:@"plist"]; 

phoneArray= [[NSMutableArray alloc]initWithContentsOfFile:path]; 

密鑰類型 項0字典 第1個字典

物品有描述,名稱鍵作爲String類型。

+1

youritems之一的plist是零... – 2012-04-15 12:16:14

回答

2

驗證你的plist,最有可能是一個壞的價值。 NSArrayNSDictionary中的項目不能爲空。您可以使用Xcode打開plist文件進行驗證。

我個人使用「PlistEdit Pro」,當plist無效時,它可以提供更好的診斷。 PlistEdit Pro有一個Free Trial here

+0

感謝Zaph。計劃有很大幫助。 – wseries 2012-04-15 19:41:37

+0

其實我錯誤地執行plist。外標籤爲,內標籤爲。再次感謝你。 – wseries 2012-04-16 01:16:09

0
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index 

要添加到數組內容的對象。該值不能爲零。

從plist文件的任何輸入之前,請檢查該元素是不是零,以避免EXCETION

+0

感謝WhiteTiger我做了NSLog(@「%@」,[dic objectForKey:@「Item 0」]); – wseries 2012-04-15 19:44:11

相關問題