objective-c:无法从堆栈跟踪中理解异常生产者的位置?

Azh*_*har -2 xcode exception objective-c ios

我是iphone开发的新手,在开发过程中由于这个错误我遇到了问题.我无法从它产生的地方追踪它.

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 -[ServerConnection 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'
Run Code Online (Sandbox Code Playgroud)

Dan*_*ite 7

这可能是一个错误.您NSMutableArray只有5个元素,并且您正在访问索引5处的第6个对象.索引是基于0的.

问题可能存在于此方法中: [ZoneFareTaxi parseMessage:]

  • 我只是从顶部走下来,这是第一件可能是你的代码. (2认同)