ios - Index 0 beyond bounds for empty array when calling addObject? -


i have nsmutablearray initializing this:

self.items = [[nsmutablearray alloc] init]; 

at point, array empty. so, add object this:

nsstring *string = @"item one"; [self.items addobject:string]; 

but app crashes , throws exception:

    *** terminating app due uncaught exception 'nsrangeexception', reason: '*** -    [__nsarraym objectatindex:]: index 0 beyond bounds empty array' *** first throw call stack: (0x3460b3e7 0x3c306963 0x34556ef9 0xad7d 0x36465569 0x3644a391 0x36461827 0x3641d8c7 0x361c9513 0x361c90b5 0x361c9fd9 0x361c99c3 0x361c97d5 0x3642393f 0x345e0941 0x345dec39 0x345def93 0x3455223d 0x345520c9 0x3813133b 0x3646e2b9 0x7a15 0x3c733b20) libc++abi.dylib: terminate called throwing exception 

my question is, know array empty, why crashing when i'm trying populate it?

the exception says all, there no errors in code have posted here. go through exception.

 **[__nsarraym objectatindex:]**: index 0 beyond bounds empty array 

it not because of [self.items addobject:string];
check code once again. calling [self.items objectatindex:0] somewhere in code when items array empty.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -