开发者

objective-c : unable to understand the exception producer place from stack trace?

开发者 https://www.devze.com 2023-04-04 21:45 出处:网络
I am new to iphone developement, during development I face problem due to this error. I am unable to trace it that from where it is produced.

I am new to iphone developement, during development I face problem due to this error. I am unable to trace it that from where it is produced.

app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x012dcbe9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x014315c2 objc_exception_throw + 47
    2   CoreFoundation                      0x012d26e5 -[__NSArrayM objectAtIndex:] + 261
    3   Dispatch                            0x0002feeb -[ZoneFareTaxi parseMessage:] + 754
    4   Dispatch                            0x0002fbf0 -[ZoneFareTaxi initWithMessageString:] + 92
    5   Dispatch                            0x0003b949 -[ServerConnecti开发者_Go百科on onUdpSocket:didReceiveData:withTag:fromHost:port:] + 8862
    6   Dispatch                            0x0002350e -[AsyncUdpSocket maybeCompleteCurrentReceive] + 458
    7   Dispatch                            0x00023210 -[AsyncUdpSocket doReceive:] + 1364
    8   Dispatch                            0x00022c60 -[AsyncUdpSocket doReceive4] + 80
    9   Dispatch                            0x00022add -[AsyncUdpSocket maybeDequeueReceive] + 561
    10  Foundation                          0x000da7f6 __NSFireDelayedPerform + 441
    11  CoreFoundation                      0x012bdfe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
    12  CoreFoundation                      0x012bf594 __CFRunLoopDoTimer + 1220
    13  CoreFoundation                      0x0121bcc9 __CFRunLoopRun + 1817
    14  CoreFoundation                      0x0121b240 CFRunLoopRunSpecific + 208
    15  CoreFoundation                      0x0121b161 CFRunLoopRunInMode + 97
    16  GraphicsServices                    0x01a4d268 GSEventRunModal + 217
    17  GraphicsServices                    0x01a4d32d GSEventRun + 115
    18  UIKit                               0x0036a42e UIApplicationMain + 1160
    19  Dispatch                            0x000024b4 main + 102
    20  Dispatch                            0x00002445 start + 53
    21  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'


This is likely an off by one error. Your NSMutableArray has only 5 elements and you are accessing the 6th object at index 5. Indexes are 0 based.

The problem resides likely in this method: [ZoneFareTaxi parseMessage:]


It should be in the parseMessage method implementation, of the class ZoneFareTaxi. In that method you send the message objectAtIndex: to an NSMutableArray object, passing a value that in that case is 5 (presumably using a variable).

It says that you are accessing to the sixth element of the array, while it has only 5 elements. Arrays are 0 indexed.


this problem only appears only if your trying to access an element from array with index is greater than your count of array.


From this:

-[NSMutableArray objectAtIndex:]: index 5 beyond bounds [0 .. 4]

you can see that you're trying to access index 5 in an array that only goes from 0 to 4.

From this:

objc_exception_throw + 47
-[__NSArrayM objectAtIndex:] + 261
-[ZoneFareTaxi parseMessage:] + 754

you can see that the problem is happening in your [ZoneFareTaxi parseMessage:] method.

0

精彩评论

暂无评论...
验证码 换一张
取 消