xcode __NSArrayM insertObject:atIndex:]:object不能为nil

时间:2012-04-15 12:15:03

标签: iphone xcode nsmutablearray plist nsdictionary

我是Xcode的新手。我想要的是在我的程序中本地读取plist数据。我有 NSArrayM insertObject:atIndex:]: object cannot be nil错误。这是我宣布的和我的plist文件。感谢

NSMutableArray *phoneArray;

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

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

密钥类型 项目0字典 第1项词典

项目有描述,名称键作为String的类型。

2 个答案:

答案 0 :(得分:2)

验证您的plist,很可能是一个糟糕的值。 NSArrayNSDictionary中的项目不能为空。您可以使用Xcode打开plist文件进行验证。

我个人使用“PlistEdit Pro”,它可以在plist无效时提供更好的诊断。有一个Free Trial here的PlistEdit Pro。

答案 1 :(得分:0)

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

要添加到数组内容的对象。该值不得为零。

在plist文件的任何输入之前,请检查元素是否为零,以避免异常