确定错误来自代码的位置 - iPhone

时间:2011-01-04 15:40:11

标签: 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 个答案:

答案 0 :(得分:3)

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

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

但我同意你的说法很难找到..如果你使用你用来打开控制台的按钮旁边的[白色和黄色]按钮,你可以检查调试器..这样你就可以点击在“2 CoreFoundation 0x011176e5 - [__ NSArrayM objectAtIndex:] + 261”上看看它出错了..

答案 1 :(得分:2)

在Apple.com上引用Xcode debugging guide以了解有关如何调试iOS应用程序的更多信息可能是一个好主意。