2011-05-11 213 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