views:

1516

answers:

1

This seems like a basic question.. but my array size is 64 and I am replacing an object at index 63. Like this:

[myMutableArray replaceObjectAtIndex:myIndex withObject:myObj];

So I have no idea why gdb is telling me this:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (64) beyond bounds (64)'

Why is it saying my index is 64? I'm passing in 63.

Thanks.

+5  A: 

Try NSLog'ing the value of myIndex just before the call, or looking for other places that could be causing this exception.

Try breaking on -[NSException raise] and/or objc_exception_throw to see where it's coming from. (See here about exception breakpoints.)

Jesse Rusak
Yes I did that, and it's 63.
hyn
Are you sure this is the line that's causing the exception?
Jesse Rusak
Doh.. sorry it was happening just after this one. Solved.
hyn
Glad to hear it. It would be kind to upvote and/or accept answers people provide that work for you. :)
Jesse Rusak
Sorry. I can't upvote yet :(
hyn
You can still accept answers, though, but you certainly don't have to.
Jesse Rusak