iphone - 确定代码中的错误来源-iPhone

标签 iphone xcode ios compiler-construction

我习惯了在Java编程中抛出错误的程序,它告诉您从哪一个文件抛出错误的行。但是使用XCode中的Objective-C,我永远无法确定错误的出处。如何找出错误的来源?这是当机错误的范例:

2011-01-04 10:36:31.645 TestGA[69958: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                      0x01121be9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x012765c2 objc_exception_throw + 47
    2   CoreFoundation                      0x011176e5 -[__NSArrayM objectAtIndex:] + 261
    3   TestGA                              0x000548d8 -[S7GraphView drawRect:] + 5763
    4   UIKit                               0x003e16eb -[UIView(CALayerDelegate) drawLayer:inContext:] + 426
    5   QuartzCore                          0x00ec89e9 -[CALayer drawInContext:] + 143
    6   QuartzCore                          0x00ec85ef _ZL16backing_callbackP9CGContextPv + 85
    7   QuartzCore                          0x00ec7dea CABackingStoreUpdate + 2246
    8   QuartzCore                          0x00ec7134 -[CALayer _display] + 1085
    9   QuartzCore                          0x00ec6be4 CALayerDisplayIfNeeded + 231
    10  QuartzCore                          0x00eb938b _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 325
    11  QuartzCore                          0x00eb90d0 _ZN2CA11Transaction6commitEv + 292
    12  QuartzCore                          0x00ee97d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
    13  CoreFoundation                      0x01102fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
    14  CoreFoundation                      0x010980e7 __CFRunLoopDoObservers + 295
    15  CoreFoundation                      0x01060bd7 __CFRunLoopRun + 1575
    16  CoreFoundation                      0x01060240 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x01060161 CFRunLoopRunInMode + 97
    18  GraphicsServices                    0x01932268 GSEventRunModal + 217
    19  GraphicsServices                    0x0193232d GSEventRun + 115
    20  UIKit                               0x003b842e UIApplicationMain + 1160
    21  TestGA                              0x00001cd8 main + 102
    22  TestGA                              0x00001c69 start + 53
    23  ???                                 0x00000001 0x0 + 1

因此,从这个角度来看,错误是从哪里来的,它是从哪个类来的?

最佳答案

2 CoreFoundation 0x011176e5-[__ NSArrayM objectAtIndex:] + 261

您正在使用该方法的数组超出范围。在这种情况下,该数组为空,您尝试从一个不存在的点获取一个值。

但是,我同意您的看法,很难找到它。如果您使用打开控制台的按钮旁边的[白色和黄色]按钮,则可以检查调试器。通过这种方式,您可以单击“2 CoreFoundation 0x011176e5-[__ NSArrayM objectAtIndex:] + 261“,然后看哪里出错了。

关于iphone - 确定代码中的错误来源-iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4595435/

相关文章:

ios - Xcode 8:iOS应用程序存档的pkg或mpkg应用程序提交验证错误

iphone - ios中bundle和resource的区别

iphone - 如何计算X秒内的数据包数量?

iphone - 停止更新位置后无法获得新位置 - IOS

ios - 我的导航器面板上的 "Info.plist"和 "Custom iOS Target Properties"有什么区别?

ios - 当用户选择 "Play Tutorial Again"时,从应用内设置再次播放 iOS 应用内教程

iphone - 如何根据时间取消 UILocalNotification

ios - 在 Swift playground 中禁用某些代码行的运行

ios - 在不使用 aws 的情况下为 RestKit 生成 S3 bucket url

ios - -retainCount 究竟有多不可靠?