'setObjectForKey:key不能为nil'异常,如何判断哪一个 [英] 'setObjectForKey: key cannot be nil' exception, how to tell which one
问题描述
我的应用程序是随机的(有时它有时不会)崩溃:
由于未捕获的异常而终止应用程序'NSInvalidArgumentException',原因:'*** setObjectForKey:key不能为nil'
***首先调用栈:
(
0 CoreFoundation 0x000000010988ec65 __exceptionPreprocess + 165
1 libobjc .A.dylib 0x000000010b63bbb7 objc_exception_throw + 45
2的CoreFoundation 0x0000000109793af8 - [__ NSDictionaryM的setObject:forKey:] + 968
3分配MultipeerConnectivity 0x00000001096e32e2 - [MCNearbyServiceBrowser netServiceBrowser:didFindService:moreComing:] + 251
4分配CFNetwork的0x000000010c2ca2dd - [NSNetServiceBrowser _dispatchCallBack:flags:error:] + 968
5 CFNetwork 0x000000010c217fe2 _ZL14_BrowserCancelP21__CFNetServiceBrowser + 133
6 CoreFoundation 0x00000001097c2431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
7分配的CoreFoundation 0x00000001097b82fd __CFRunLoopDoSources0 + 269
8分配的CoreFoundation 0x00000001097b7934 __CFRunLoopRun + 868
9分配的CoreFoundation 0x00000001097b7366 CFRunLoopRunSpecific + 470
10个分配GraphicsServices 0x000000010d1a3a3e GSEventRunModal + 161
11分配的UIKit 0x000000010a36f8c0 UIApplicationMain + 1282
12 MyApp 0x0000000109099137 main + 135
13 libdyld.dylib 0x000000010cccc145 start + 1
)
libc ++ abi.dylib:以NSException类型的未捕获异常终止
如何在Xcode中知道哪行代码或集合对象是否导致问题? >
更新
我做了ans wer和评论建议,并添加了断点与命令,现在,在错误之前,我得到这样:
*** setObjectForKey :钥匙不能为零
4354859399
3534170
140567501647968
140567492355160
140567492355168
4354751672
4294967279
我还不知道这是什么意思。
在Xcode的左侧面板中,转到断点选项卡,单击 +
按钮,并添加一个
异常断点
。它将捕获任何异常并告诉您他们发生的地方。
My app is randomly (sometimes it does, sometimes it doesn't) crashing:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x000000010988ec65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010b63bbb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000109793af8 -[__NSDictionaryM setObject:forKey:] + 968
3 MultipeerConnectivity 0x00000001096e32e2 -[MCNearbyServiceBrowser netServiceBrowser:didFindService:moreComing:] + 251
4 CFNetwork 0x000000010c2ca2dd -[NSNetServiceBrowser _dispatchCallBack:flags:error:] + 968
5 CFNetwork 0x000000010c217fe2 _ZL14_BrowserCancelP21__CFNetServiceBrowser + 133
6 CoreFoundation 0x00000001097c2431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
7 CoreFoundation 0x00000001097b82fd __CFRunLoopDoSources0 + 269
8 CoreFoundation 0x00000001097b7934 __CFRunLoopRun + 868
9 CoreFoundation 0x00000001097b7366 CFRunLoopRunSpecific + 470
10 GraphicsServices 0x000000010d1a3a3e GSEventRunModal + 161
11 UIKit 0x000000010a36f8c0 UIApplicationMain + 1282
12 MyApp 0x0000000109099137 main + 135
13 libdyld.dylib 0x000000010cccc145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
How can I tell in Xcode which line of code, or collection object is causing the problem?
Update
I did as the answer and comments suggested, and added the breakpoint with the command, and now, before the error, I get this:
*** setObjectForKey: key cannot be nil
4354859399
3534170
140567501647968
140567492355160
140567492355168
4354751672
4294967279
I still don't know what that means...
In your Xcode's left panel, go to the Breakpoints tab, click the +
button and add an Exception Breakpoint
. It will catch any exception and tell you where they occur.
这篇关于'setObjectForKey:key不能为nil'异常,如何判断哪一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!