Obj-C - Cocoa Mac:SIGABRT错误

时间:2013-11-04 21:07:18

标签: objective-c macos cocoa

我正在为Imgur for mac编写客户端代码,允许用户拖放图片然后上传。我刚刚完成了UploadToImgur函数的编码,现在我收到了一个SIGABRT错误:

int main(int argc, char *argv[])
{
   return NSApplicationMain(argc, (const char **)argv);
}

为了澄清,在我单击我编码的上传按钮后发生SIGABRT错误,该按钮基本上拍摄图像,将其转换为NSData,然后将其发送到uploadToImgur。可以为两个适用的函数提供代码。

控制台说:

2013-11-04 16:04:22.641 Popup[11274:303] Uploading image.
2013-11-04 16:04:33.602 Popup[11274:303] Server reached successfully.
2013-11-04 16:04:33.603 Popup[11274:303] URL: (null)
2013-11-04 16:04:33.603 Popup[11274:303] *** Assertion failure in -[NSTextFieldCell _objectValue:forString:errorDescription:], /SourceCache/AppKit/AppKit-1265/AppKit.subproj/NSCell.m:1637
2013-11-04 16:04:33.606 Popup[11274:303] An uncaught exception was raised
2013-11-04 16:04:33.606 Popup[11274:303] Invalid parameter not satisfying: aString != nil
2013-11-04 16:04:33.606 Popup[11274:303] (
    0   CoreFoundation                      0x00007fff92fd441c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff8f69fe75 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff92fd41f8 +[NSException raise:format:arguments:] + 104
    3   Foundation                          0x00007fff90ff9c61 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
    4   AppKit                              0x00007fff8ba4f918 -[NSCell _objectValue:forString:errorDescription:] + 159
    5   AppKit                              0x00007fff8ba4f86a -[NSCell _objectValue:forString:] + 20
    6   AppKit                              0x00007fff8ba4f7d8 -[NSCell setStringValue:] + 41
    7   AppKit                              0x00007fff8bacb584 -[NSControl setStringValue:] + 138
    8   Popup                               0x0000000100004983 __39-[PanelController btnUploadWasClicked:]_block_invoke_2 + 131
    9   libdispatch.dylib                   0x00007fff895d71d7 _dispatch_call_block_and_release + 12
    10  libdispatch.dylib                   0x00007fff895d42ad _dispatch_client_callout + 8
    11  libdispatch.dylib                   0x00007fff895dbf03 _dispatch_main_queue_callback_4CF + 333
    12  CoreFoundation                      0x00007fff92f3b839 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    13  CoreFoundation                      0x00007fff92ef6b14 __CFRunLoopRun + 1636
    14  CoreFoundation                      0x00007fff92ef6275 CFRunLoopRunSpecific + 309
    15  HIToolbox                           0x00007fff8e217f0d RunCurrentEventLoopInMode + 226
    16  HIToolbox                           0x00007fff8e217cb7 ReceiveNextEventCommon + 479
    17  HIToolbox                           0x00007fff8e217abc _BlockUntilNextEventMatchingListInModeWithFilter + 65
    18  AppKit                              0x00007fff8ba1028e _DPSNextEvent + 1434
    19  AppKit                              0x00007fff8ba0f8db -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
    20  AppKit                              0x00007fff8ba039cc -[NSApplication run] + 553
    21  AppKit                              0x00007fff8b9ee803 NSApplicationMain + 940
    22  Popup                               0x00000001000018b2 main + 34
    23  Popup                               0x0000000100001884 start + 52
)
2013-11-04 16:04:33.610 Popup[11274:303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: aString != nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff92fd441c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff8f69fe75 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff92fd41f8 +[NSException raise:format:arguments:] + 104
    3   Foundation                          0x00007fff90ff9c61 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
    4   AppKit                              0x00007fff8ba4f918 -[NSCell _objectValue:forString:errorDescription:] + 159
    5   AppKit                              0x00007fff8ba4f86a -[NSCell _objectValue:forString:] + 20
    6   AppKit                              0x00007fff8ba4f7d8 -[NSCell setStringValue:] + 41
    7   AppKit                              0x00007fff8bacb584 -[NSControl setStringValue:] + 138
    8   Popup                               0x0000000100004983 __39-[PanelController btnUploadWasClicked:]_block_invoke_2 + 131
    9   libdispatch.dylib                   0x00007fff895d71d7 _dispatch_call_block_and_release + 12
    10  libdispatch.dylib                   0x00007fff895d42ad _dispatch_client_callout + 8
    11  libdispatch.dylib                   0x00007fff895dbf03 _dispatch_main_queue_callback_4CF + 333
    12  CoreFoundation                      0x00007fff92f3b839 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    13  CoreFoundation                      0x00007fff92ef6b14 __CFRunLoopRun + 1636
    14  CoreFoundation                      0x00007fff92ef6275 CFRunLoopRunSpecific + 309
    15  HIToolbox                           0x00007fff8e217f0d RunCurrentEventLoopInMode + 226
    16  HIToolbox                           0x00007fff8e217cb7 ReceiveNextEventCommon + 479
    17  HIToolbox                           0x00007fff8e217abc _BlockUntilNextEventMatchingListInModeWithFilter + 65
    18  AppKit                              0x00007fff8ba1028e _DPSNextEvent + 1434
    19  AppKit                              0x00007fff8ba0f8db -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
    20  AppKit                              0x00007fff8ba039cc -[NSApplication run] + 553
    21  AppKit                              0x00007fff8b9ee803 NSApplicationMain + 940
    22  Popup                               0x00000001000018b2 main + 34
    23  Popup                               0x0000000100001884 start + 52
)
libc++abi.dylib: terminating with uncaught exception of type NSException

有什么想法吗?可以提供更多信息。

2 个答案:

答案 0 :(得分:0)

问题似乎是你向方法传递了错误的参数。只需输入断点并检查一些您输入了错误参数的行。

答案 1 :(得分:0)

显示窗口时,关联的文本字段不能设置为nil。如果将NSTextField字符串值设置为nil,您将看到此问题。因此,要解决此问题,请确保不要将它们设置为nil。

声明:

IBOutlet NSTextField *username;

实现:

- (id)initWithWindow:(NSWindow *)window
{
    self = [super initWithWindow:window];
    if (self) {
        [username setStringValue:@"User"];
    }
    return self;
}