确定代码中的错误来自何处 - iPhone

问题描述 投票:0回答:2

我习惯了 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

那么从这里来看,错误来自哪里,来自哪个类?

ios objective-c iphone xcode
2个回答
3
投票

2 CoreFoundation 0x011176e5 -[__NSArrayM objectAtIndex:] + 261

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

但我同意你的观点,它很难找到。如果你使用打开控制台的按钮旁边的[白色和黄色]按钮,你可以检查调试器。这样你就可以单击“ 2 CoreFoundation 0x011176e5 -[__NSArrayM objectAtIndex:] + 261” 看看哪里出了问题..


2
投票

最好参考 Apple.com 上的 Xcode 调试指南,了解有关如何调试 iOS 应用程序的更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.