views:

480

answers:

4

2009-07-21 12:47:14.458 FlashCards[1328:20b] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)'

A: 

Looks like you are trying to access an element in an array that does not exist. You are trying the get the 0th element (the first) but the array has a size of 0 (it's empty).

Start by checking in your code for where you are using arrays and the objectAtIndex: method and then sanity check the array sizes while debugging.

teabot
A: 

It looks like your application is trying to get the first item from an empty NSCFArray. Does the debugger not point you to the location in the source code causing the exception?

Kim Gräsman
no it only shows this error
Rahul Vyas
Do you know where in your app you are using an NSCFArray? If so, I would go there and try to isolate a scenario where indexing could get out of bounds.
Kim Gräsman
i am not using any NSCFArray...i think it's the stack array which is of navigation controller have
Rahul Vyas
A: 

That is your standard array out of bounds exception. I would pull up the debugger and attempt to figure out which array this is. If you do not know, check for which arrays do not have any elements in them, and set breakpoints before using the function objectAtIndex:xyz.

TahoeWolverine
Breaking on exceptions is much easier (and less error prone, since there's no guarantee this is not an indirect call through one of the frameworks) than doing source inspection and breaking on all the calls.
smorgan
Good point. Unless I misunderstand what you mean, that requires some overhead and has never been worth it on my projects, since an array out of bounds exception is pretty easy to find and fix.
TahoeWolverine
I don't know what overhead you are referring to. You set two breakpoints (-[NSException raise] and objc_exception_throw) then run until it breaks. Print the stack, and you are done.
smorgan
Fair enough. I have never set breakpoints in apple code...it's great to know that I can do that.
TahoeWolverine
A: 

See the answer to this question for information about how to find out exactly where your exception is being raised using the debugger.

smorgan