2011-05-11 160 views
2

作为Xcode新手的Java和PHP开发人员,我无法处理内存错误。我有一本书的示例程序,它在启动时与“程序接收信号SIGABRT”崩溃。“我不知道如何处理下面的控制台输出。我意识到这是某种堆栈跟踪,但左侧的名称只是应用程序的名称,而不是类或文件。我不知道“main + 121”或“start + 53”是指什么或在哪里寻找。任何指导将不胜感激。如何读取Xcode控制台输出?

2011-05-11 10:43:23.071 FlowerInfoNavigator[22537:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFDictionary objectForKey:]: method sent to an uninitialized mutable dictionary object' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x00dc25a9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x00f16313 objc_exception_throw + 44 
    2 CoreFoundation      0x00dbf542 -[__NSPlaceholderDictionary objectForKey:] + 194 
    3 FlowerInfoNavigator     0x0000289a -[RootViewController tableView:didSelectRowAtIndexPath:] + 330 
    4 UIKit        0x0008bb68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140 
    5 UIKit        0x00081b05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219 
    6 Foundation       0x0079b79e __NSFireDelayedPerform + 441 
    7 CoreFoundation      0x00da38c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19 
    8 CoreFoundation      0x00da4e74 __CFRunLoopDoTimer + 1220 
    9 CoreFoundation      0x00d012c9 __CFRunLoopRun + 1817 
    10 CoreFoundation      0x00d00840 CFRunLoopRunSpecific + 208 
    11 CoreFoundation      0x00d00761 CFRunLoopRunInMode + 97 
    12 GraphicsServices     0x00ffa1c4 GSEventRunModal + 217 
    13 GraphicsServices     0x00ffa289 GSEventRun + 115 
    14 UIKit        0x00022c93 UIApplicationMain + 1160 
    15 FlowerInfoNavigator     0x00001b99 main + 121 
    16 FlowerInfoNavigator     0x00001b15 start + 53 
) 
terminate called after throwing an instance of 'NSException' 
(gdb) 

回答

4

右边是被调用的堆栈上的方法。我通常只是寻找来自我的一个方法的任何东西(尽管这并不总是有效),然后它会给你发出问题的方法调用。在“FlowerInfoNavigator”上的呼叫号码3的跟踪中,方法tableView:didSelectRowAtIndexPath:被调用,并且在那里导致崩溃。你应该能够使用调试器和断点从希望的地方缩小它的范围。祝你好运。

编辑:当我再次看到你的错误信息:在它的顶部,它给你的错误。您试图从尚未初始化的NSDictionary中检索一个对象,并且从上面发生,它发生在您的didSelectRowAtIndexPath方法中

+0

谢谢。你的回答让我能够理解控制台,足以发现哪里出了问题。 – BobH 2011-05-13 01:55:53

0

控制台不会是您唯一看的地方。看看你的调试器了。那边通常有一条加粗的线。如果你点击它,它会告诉你到底发生了什么事。

貌似你没有初始化你NSDictionary

0

的崩溃是由于NSDictionary中尚未初始化以及如何崩溃,首先看一下控制台中搜索,所以你会得到什么导致崩溃的想法或异常,并得到应用程序崩溃的位置,您可以检出调试器。在调试器中,应用程序崩溃时,特殊行将以粗体显示。

除此之外,你还可以使用NSZombieEnabled(BOOL)得到什么导致应用程序崩溃。更多关于NSZombieEnabled可以在这里找到http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/130-Debugging_Applications/debugging_applications.html

注:此处做确保使NSZombieEnabled设置为NO在时间处理应用程序以提交给苹果商店。

希望这会有所帮助。

+0

其实,字典已初始化,但我正在把一个字符串放在图像应该去的地方。还是)感谢你的建议。 gdb看起来像是在编程工具中落后10年或15年。 – BobH 2011-05-13 01:58:00