使用聊天应用程序XMPPFramework我收到此错误

时间:2015-01-09 13:17:02

标签: ios iphone

将聊天应用程序与XMPPFramework一起使用我收到此错误  消息SendButton动作如下,plz帮助我,如果任何人有想法然后告诉我PLZ ..............

- (IBAction)sendAction:(id)sender
            {
                if([_chatTextField.text length] > 0)
                {
                    NSString* po = getUser.ofUser;
                    bubbleTable.typingBubble = NSBubbleTypingTypeNobody;
                    NSBubbleData *messageBubble = [NSBubbleData dataWithText:_chatTextField.text date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine];
                    [bubbleData addObject:messageBubble];
                    [bubbleTable reloadData];
                    [bubbleTable scrollBubbleViewToBottomAnimated:YES];


                    [[QuoteMessageController SharedInstance] SendChatMessageTo:getUser.account withContent:_chatTextField.text toUserId:[NSString stringWithFormat:@"%ld", (long)getUser.Id] andOFId:po andVerifyKey:chatMessageKey];
                }

输出中的错误如下所示>>>>>>>

        *** First throw call stack:
        (
            0   CoreFoundation                      0x000000010e18ff35 __exceptionPreprocess + 165
            1   libobjc.A.dylib                     0x000000010da7bbb7 objc_exception_throw + 45
            2   CoreFoundation                      0x000000010e18fe6d +[NSException raise:format:] + 205
            3   Foundation                          0x000000010ba211f8 -[NSString stringByAppendingString:] + 96
            4   SourceSage                          0x000000010ae0c939 +[SSWriteReadInDb writeQuotesTable:UserImageUrl:UserId:OfUser:] + 409
            5   SourceSage                          0x000000010adb8d56 -[QuoteMessageController SendChatMessageTo:withContent:toUserId:andOFId:andVerifyKey:] + 2454
            6   SourceSage                          0x000000010ad6ac30 -[SSChatViewController sendAction:] + 752
            7   UIKit                               0x000000010beb48be -[UIApplication sendAction:to:from:forEvent:] + 75
            8   UIKit                               0x000000010bfbb410 -[UIControl _sendActionsForEvents:withEvent:] + 467
            9   UIKit                               0x000000010bfba7df -[UIControl touchesEnded:withEvent:] + 522
            10  UIKit                               0x000000010befa308 -[UIWindow _sendTouchesForEvent:] + 735
            11  UIKit                               0x000000010befac33 -[UIWindow sendEvent:] + 683
            12  UIKit                               0x000000010bec79b1 -[UIApplication sendEvent:] + 246
            13  UIKit                               0x000000010bed4a7d _UIApplicationHandleEventFromQueueEvent + 17370
            14  UIKit                               0x000000010beb0103 _UIApplicationHandleEventQueue + 1961
            15  CoreFoundation                      0x000000010e0c5551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
            16  CoreFoundation                      0x000000010e0bb41d __CFRunLoopDoSources0 + 269
            17  CoreFoundation                      0x000000010e0baa54 __CFRunLoopRun + 868
            18  CoreFoundation                      0x000000010e0ba486 CFRunLoopRunSpecific + 470
            19  GraphicsServices                    0x000000010fe7c9f0 GSEventRunModal + 161
            20  UIKit                               0x000000010beb3420 UIApplicationMain + 1282
            21  SourceSage                          0x000000010ae02893 main + 115
            22  libdyld.dylib                       0x000000010ee2e145 start + 1
            23  ???                                 0x0000000000000001 0x0 + 1
        )
        libc++abi.dylib: terminating with uncaught exception of type NSException
        (lldb) 

1 个答案:

答案 0 :(得分:0)

查看堆栈跟踪的这一部分后:

2   CoreFoundation     0x000000010e18fe6d +[NSException raise:format:] + 205
3   Foundation         0x000000010ba211f8 -[NSString stringByAppendingString:] + 96
4   SourceSage         0x000000010ae0c939 +[SSWriteReadInDb writeQuotesTable:UserImageUrl:UserId:OfUser:] + 409
5   SourceSage         0x000000010adb8d56 -[QuoteMessageController SendChatMessageTo:withContent:toUserId:andOFId:andVerifyKey:] + 2454
6   SourceSage         0x000000010ad6ac30 -[SSChatViewController sendAction:] + 752

您会看到在将字符串附加到字符串后引发异常。这通常是因为将nil附加到字符串。猜猜您发送给以下方法的NSString个参数之一是nil

[[QuoteMessageController SharedInstance] SendChatMessageTo:getUser.account
     withContent:_chatTextField.text 
     toUserId:[NSString stringWithFormat:@"%ld", (long)getUser.Id] 
     andOFId:po
     andVerifyKey:chatMessageKey];

要查明是否确实如此,请在此处设置断点并检查所有值,或在调用此方法之前添加以下内容:

NSLog(@"%@", getUser.account);
NSLog(@"%@", _chatTextField.text);
NSLog(@"%@", po);
NSLog(@"%@", [NSString stringWithFormat:@"%ld", (long)getUser.Id]);
NSLog(@"%@", chatMessageKey);

我不知道您的参数究竟是什么,因此请删除NSLog以查找非NSString的变量。如果其中一个日志返回nilnull(我忘记了控制台将输出的内容),那么您就找到了问题。如果这是您不一定需要的参数,则应该传递空的NSString。我通常用三元组来做这件事。因此,假设罪魁祸首是_chatTextField.text,我会将该论点传递为:

[[QuoteMessageController SharedInstance] SendChatMessageTo:getUser.account
     withContent:_chatTextField.text ?: @""
     toUserId:[NSString stringWithFormat:@"%ld", (long)getUser.Id] 
     andOFId:po
     andVerifyKey:chatMessageKey];

这样做基本上说,如果_chatTextField.text为真(如果它不是nill则相等),请使用该值,否则使用@""

编辑:

- (IBAction)sendAction:(id)sender
{
    if([_chatTextField.text length] > 0)
    {
        NSString* po = getUser.ofUser ?: @"";
        NSString *acct = getUser.account ?: @"";
        bubbleTable.typingBubble = NSBubbleTypingTypeNobody;
        NSBubbleData *messageBubble = [NSBubbleData dataWithText:_chatTextField.text date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine];
        [bubbleData addObject:messageBubble];
        [bubbleTable reloadData];
        [bubbleTable scrollBubbleViewToBottomAnimated:YES];


        [[QuoteMessageController SharedInstance] SendChatMessageTo:acct withContent:_chatTextField.text toUserId:[NSString stringWithFormat:@"%ld", (long)getUser.Id] andOFId:po andVerifyKey:chatMessageKey];
}