-[__ NSArrayM insertObject:atIndex:]:对象不能为nil [英] -[__NSArrayM insertObject:atIndex:]: object cannot be nil
问题描述
我得到的错误对象不能为nil.我正在使用Web服务,当我使用循环对其进行解析时,它崩溃并发送输出-[__ NSArrayM insertObject:atIndex:]:
对象不能为nil作为错误,因为我在<我正在尝试解析的code> NSMutableArray .
I am getting error object cannot be nil. I am using web service, when I parse it using loop it crashed and send output -[__NSArrayM insertObject:atIndex:]:
object cannot be nil as error, because I have null value on blank value in NSMutableArray
which I am trying to parse.
我尝试使用以下方法进行修复:
I tried to fix with these methods:
(1) if([Array containsObject:[NSNull null]])
(2) if([Array objectAtIndex:0
(3) if([Array objectAtIndex:counter] == 0**
我的代码是
if([[[node childAtIndex:counter] name] isEqualToString:@"Phone"]){
if([phoneno containsObject:[NSNull null]]){
phone.text = @"-";
}
else{
NSString *str = [[node childAtIndex:counter] stringValue];
[phoneno addObject:str];
NSString *myString = [phoneno componentsJoinedByString:@","];
[phone setText:myString];
phone.text = [NSString stringWithFormat:@"%@",myString];
}
}
在这里,电话号码是NSMutableArray
Here, phoneno is NSMutableArray
推荐答案
在添加任何对象之前,请确保已初始化名为phoneno的数组.
Make sure you have initialized your array called phoneno before adding any object into it...
NSMutableArray *phoneno=[[NSMutableArray alloc]init];
并停止向其中添加任何nil对象...
and stop adding any nil object into it...
if(str) //or if(str != nil) or if(str.length>0)
{
//add the str into phoneno array.
}
else
{
//add the @""
}
这篇关于-[__ NSArrayM insertObject:atIndex:]:对象不能为nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!