0

I have this code:

if (self.leadObject != nil) {
    [result addObject:self.leadObject];
}

And sometimes app close with this error:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

The execution pass if command and try to add the object self.leadObject inside of result array although this object is nil. Can someone explain this??

Update:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: (0x2ca8af87 0x3a1e9c77 0x2c9a6f29 0x1777ff 0x177a6f 0x177b7f 0x1779df 0x17446d 0xa1cdd 0xa7933 0x46cad3 0x46cabf 0x47051b 0x2ca50e61 0x2ca4f581 0x2c99cdb1 0x2c99cbc3 0x33d28051 0x2ff68a31 0xadb45 0x3a785aaf) libc++abi.dylib: terminating with uncaught exception of type NSException

16
  • 1
    are you sure the crash is caused at this part? I'd recommend adding a log statemenent before [result addObject:self.leadObject] where you print the value of self.leadObject, just to make sure... Commented Jan 15, 2015 at 14:07
  • 1
    Please paste a copy of the stack trace from the crash log into your question. Commented Jan 15, 2015 at 14:08
  • 1
    Are you sure you aren't calling insertObject:atIndex: somewhere? Commented Jan 15, 2015 at 14:26
  • 2
    Please show the definition of the declared property leadObject if there is one, otherwise the ivar definition and the definition of the getter, if it is not synthesized. Commented Jan 15, 2015 at 16:19
  • 1
    @FernandoGarcíaCorrochano I used another library, because I couldn't solve the problem Commented Jan 21, 2016 at 16:31

1 Answer 1

-2

I suspect that you have not allocated your result object. Do so if you didn't and then Log the self.leadObject to make sure that it isn't an NSNull

if (self.leadObject) {
    NSLog(@"%@", self.leadObject);
    [result addObject:self.leadObject];
}
Sign up to request clarification or add additional context in comments.

1 Comment

if leadObject were an NSNull object then there would be no error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.