由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:[__ NSArrayI length]:无法识别的选择器发送到实例

时间:2016-02-11 05:21:42

标签: ios objective-c

以下是我的示例错误

  

2016-02-10 13:02:15.335 redminete [5804:56271]    - [ NSArrayI长度]:无法识别的选择器发送到实例0x7fd0e3483470 2016-02-10 13:02:15.361 redminete [5804:56271] ***   由于未捕获的异常而终止应用程序   ' NSInvalidArgumentException',原因:' - [__ NSArrayI长度]:   无法识别的选择器发送到实例0x7fd0e3483470'   ***首先抛出调用堆栈:(0 CoreFoundation 0x000000010ac89c65 __exceptionPreprocess + 165 1 libobjc.A.dylib
  0x000000010a922bb7 objc_exception_throw + 45 2 CoreFoundation
  0x000000010ac910ad - [NSObject(NSObject)doesNotRecognizeSelector:] +   205 3 CoreFoundation 0x000000010abe713c   ___转发_
+ 988 4 CoreFoundation 0x000000010abe6cd8 _CF_forwarding_prep_0 + 120 5 UIKit
  0x000000010b258e9c - [UILabel _ensureBaselineMetricsReturningBounds] +   138 6 UIKit 0x000000010b259082    - [UILabel _firstBaselineOffsetFromTop] + 36 7 UIKit 0x000000010b70003d - [UIView(AdditionalLayoutSupport)   nsli_lowerAttribute:intoExpression:withCoefficient:forConstraint:] +   1287 8基金会0x000000010a4be9ae   lower_1_attribute + 158 9基金会   0x000000010a4be4c4 - [NSLayoutConstraint   _lowerIntoExpression:reportingConstantIsRounded:] + 102 10 Foundation 0x000000010a4b441e    - [NSLayoutConstraint _addToEngine:integralizationAdjustment:mutualExclusiveConstraints:] + 96 11 UIKit 0x000000010b6fd8d4 57- [UIView(AdditionalLayoutSupport)_switchToLayoutEngine:] _ block_invoke_2 + 474 12 Foundation 0x000000010a4c21be - [NSISEngine withBehaviors:performModifications:] +   155 13 UIKit 0x000000010b6fd6da   __57- [UIView(AdditionalLayoutSupport)_switchToLayoutEngine:] _ block_invoke + 452 14 UIKit 0x000000010b6fd4ed - [UIView(AdditionalLayoutSupport)   _switchToLayoutEngine:] + 197 15 UIKit 0x000000010b6fd7d3 __57- [UIView(AdditionalLayoutSupport)   _switchToLayoutEngine:] _ block_invoke_2 + 217 16 Foundation 0x000000010a4c21be - [NSISEngine withBehaviors:performModifications:] +   155 17 UIKit 0x000000010b6fd6da   __57- [UIView(AdditionalLayoutSupport)_switchToLayoutEngine:] _ block_invoke + 452 18 UIKit 0x000000010b6fd4ed - [UIView(AdditionalLayoutSupport)   _switchToLayoutEngine:] + 197 19 UIKit 0x000000010b10b7c5 - [UIScrollView _switchToLayoutEngine:] + 69 20   UIKit 0x000000010b6fd7d3   __57- [UIView(AdditionalLayoutSupport)_switchToLayoutEngine:] _ block_invoke_2 + 217 21 Foundation 0x000000010a4c21be - [NSISEngine withBehaviors:performModifications:] +   155 22 UIKit 0x000000010b6fd6da   __57- [UIView(AdditionalLayoutSupport)_switchToLayoutEngine:] _ block_invoke + 452 23 UIKit 0x000000010b6fd4ed - [UIView(AdditionalLayoutSupport)   _switchToLayoutEngine:] + 197 24 UIKit 0x000000010b6fd7d3 __57- [UIView(AdditionalLayoutSupport)   _switchToLayoutEngine:] _ block_invoke_2 + 217 25基础0x000000010a4c21be - [NSISEngine withBehaviors:performModifications:] +   155 26 UIKit 0x000000010b6fd6da   __57- [UIView(AdditionalLayoutSupport)_switchToLayoutEngine:] _ block_invoke + 452 27 UIKit 0x000000010b6fd4ed - [UIView(AdditionalLayoutSupport)   _switchToLayoutEngine:] + 197 28 UIKit 0x000000010b6fd7d3 __57- [UIView(AdditionalLayoutSupport)   _switchToLayoutEngine:] _ block_invoke_2 + 217 29基金会0x000000010a4c21be - [NSISEngine withBehaviors:performModifications:] +   155 30 UIKit 0x000000010b6fd6da   __57- [UIView(AdditionalLayoutSupport)_switchToLayoutEngine:] _ block_invoke + 452 31 UIKit 0x000000010b6fd4ed - [UIView(AdditionalLayoutSupport)   _switchToLayoutEngine:] + 197 32 UIKit 0x000000010b6fd7d3 __57- [UIView(AdditionalLayoutSupport)   _switchToLayoutEngine:] _ block_invoke_2 + 217 33基础0x000000010a4c21be - [NSISEngine withBehaviors:performModifications:] +   155 34 UIKit 0x000000010b6fd6da   __57- [UIView(AdditionalLayoutSupport)_switchToLayoutEngine:] _ block_invoke + 452 35 UIKit 0x000000010b6fd4ed - [UIView(AdditionalLayoutSupport)   _switchToLayoutEngine:] + 197 36 UIKit 0x000000010b0f66d7 __40- [UIView(Hierarchy)   layoutBelowIfNeeded] _block_invoke + 39 37基金会   0x000000010a4c21be - [NSISEngine withBehaviors:performModifications:] +   155 38 UIKit 0x000000010b0f6516    - [UIView(Hierarchy)layoutBelowIfNeeded] + 320 39 UIKit 0x000000010b48b234 - [_ UIAlertControllerAnimatedTransitioning   animateTransition:] + 470 40 UIKit
  0x000000010b190a0e __56- [UIPresentationController   runTransitionForCurrentState] _block_invoke + 1867 41 UIKit
  0x000000010b0a65ec _applyBlockToCFArrayCopiedToStack + 314 42 UIKit   0x000000010b0a6466 _afterCACommitHandler + 533 43 CoreFoundation
  0x000000010abbcca7   __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 23 44 CoreFoundation 0x000000010abbcc00   __CFRunLoopDoObservers + 368 45 CoreFoundation 0x000000010abb2a33 __CFRunLoopRun + 1123 46 CoreFoundation
  0x000000010abb2366 CFRunLoopRunSpecific + 470 47图形服务
  0x000000010e1afa3e GSEventRunModal + 161 48 UIKit
  0x000000010b0828c0 UIApplicationMain + 1282 49 redminete
  0x000000010a3dbc33 main + 99 50 libdyld.dylib
  0x000000010d22d145 start + 1)libc ++ abi.dylib:终止于   NSException类型的未捕获异常

以下是我的示例代码

 -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{

    [self.receivedData appendData:data];
    NSString *htmlSTR = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    @try {
        if([htmlSTR isEqualToString:@"Successful update."])
        {
            NSString * storyboardName=@"Main";
            UIStoryboard *storyboard =[UIStoryboard storyboardWithName:storyboardName bundle:nil];
            UITabBarController *tabBar =[storyboard instantiateViewControllerWithIdentifier:@"MainTabBar"];

            [self presentViewController:tabBar animated:YES completion:Nil];
        }
        else
        {
            id jsonObjects = [NSJSONSerialization JSONObjectWithData:
                              data options:NSJSONReadingMutableContainers error:nil];
            NSString *errorMsg = [jsonObjects objectForKey:@"errors"];
             [self alertView:@"Error Message" andMessage:errorMsg];
            NSLog(@"%@" , errorMsg);
        }

    }
    @catch (NSException *exception) {
          NSString *errorMsg = [NSString stringWithFormat:@"%@",exception];
         [self alertView:@"Error Message" andMessage:errorMsg];
    }

}

-(void) alertView:(NSString *) title andMessage:(NSString *) message
{

    UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:title
                                                     message:message
                                                    delegate:self
                                           cancelButtonTitle:@"OK"
                                           otherButtonTitles: nil];
    [alert show];
}

1 个答案:

答案 0 :(得分:0)

此行[jsonObjects objectForKey:@"errors"]很可能会返回一系列错误,您将其视为NSString