Index 0 outside for an empty array error

I do not understand how to debug this error message:

2011-02-01 20:45:56.151 NeMe[3206:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array' *** Call stack at first throw: ( 0 CoreFoundation 0x027deb99 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x0292e40e objc_exception_throw + 47 2 CoreFoundation 0x027d4695 -[__NSArrayM objectAtIndex:] + 261 3 NeighborMe 0x0000f617 -[NeighborMapViewController regionFromLocations] + 65 4 NeighborMe 0x0001047b -[NeighborMapViewController locationManager:didUpdateToLocation:fromLocation:] + 94 5 CoreLocation 0x02393870 -[CLLocationManager onClientEventLocation:] + 793 6 CoreLocation 0x0239218b OnClientEvent + 49 7 CoreLocation 0x023a8a83 _Z22CLClientInvokeCallbackP10__CLClient13CLClientEventPK14__CFDictionary + 47 8 CoreLocation 0x023a9b2c _Z27CLClientHandleDaemonDataFixP10__CLClientPK23CLDaemonCommToClientFixPK14__CFDictionary + 290 9 CoreLocation 0x023acb30 _Z24CLClientHandleDaemonDataP12__CFMachPortPvlS1_ + 1125 10 CoreFoundation 0x02720982 __CFMachPortPerform + 338 11 CoreFoundation 0x027bfff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 12 CoreFoundation 0x02720807 __CFRunLoopDoSource1 + 215 13 CoreFoundation 0x0271da93 __CFRunLoopRun + 979 14 CoreFoundation 0x0271d350 CFRunLoopRunSpecific + 208 15 CoreFoundation 0x0271d271 CFRunLoopRunInMode + 97 16 GraphicsServices 0x030bd00c GSEventRunModal + 217 17 GraphicsServices 0x030bd0d1 GSEventRun + 115 18 UIKit 0x002eeaf2 UIApplicationMain + 1160 19 NeighborMe 0x00002818 main + 102 20 NeighborMe 0x000027a9 start + 53 21 ??? 0x00000001 0x0 + 1 ) terminate called after throwing an instance of 'NSException' 

There is NSMutableArray in this code ... so how is this possible?

+8
objective-c iphone
source share
3 answers

You have an empty array. You tried to call [array objectAtIndex:0] . 0 goes beyond an empty array (unsurprisingly - everything goes beyond an empty array).

+29
source share

This means that at the beginning of [NeighborMapViewController regionFromLocations] you are trying to index an NSMutableArray. This array has zero elements in it - it is empty. But you are apparently trying to access index 0, which will be the first element. Since the first element is missing, you get an exception.

The code that you expected to execute to add elements to the array is probably not executed yet, or you just need to check the length of the array before trying to access the element at index 0. It's hard to say without knowing more about what you are doing.

gdb reports an offset of 65 bytes per function, therefore, probably in one of the first few lines. You could probably manually check the function code to see, or set a breakpoint in the first line of the function and go through it.

+4
source share

I saw this error, however, not as an exception, but only in the Problem Navigator. The solution was to simply restart Xcode, then the error went away.

0
source share

All Articles