libc ++ abi.dylib:以NSException类型的未捕获异常终止:获取此线程

时间:2016-02-09 06:14:51

标签: objective-c

2016-02-09 11:25:11.773 TableView [1408:94586] *由于未捕获的异常'NSRangeException'终止应用程序,原因:'* - [ NSArray0 objectAtIndex:] :索引0超出空NSArray的边界' ***第一次抛出调用堆栈: (     0 CoreFoundation 0x0000000111c5fe65 __exceptionPreprocess + 165     1 libobjc.A.dylib 0x00000001116d6deb objc_exception_throw + 48     2 CoreFoundation 0x0000000111c0e395 - [__ NSArray0 objectAtIndex:] + 101     3 TableView 0x000000010f949046 - [FlightDetailsViewController loadInfoToEdit] + 310     4 TableView 0x000000010f94887d - [FlightDetailsViewController viewDidLoad] + 509     5 UIKit 0x0000000110348f98 - [UIViewController loadViewIfRequired] + 1198     6 UIKit 0x000000011034ef4f - [UIViewController __viewWillAppear:] + 120     7 UIKit 0x000000011037ee44 - [UINavigationController _startCustomTransition:] + 1203     8 UIKit 0x000000011038f23f - [UINavigationController _startDeferredTransitionIfNeeded:] + 712     9 UIKit 0x00000001103903af - [UINavigationController __viewWillLayoutSubviews] + 57     10 UIKit 0x0000000110536ff7 - [UILayoutContainerView layoutSubviews] + 248     11 UIKit 0x00000001102694a3 - [UIView(CALayerDelegate)layoutSublayersOfLayer:] + 703     12 QuartzCore 0x000000011507759a - [CALayer layoutSublayers] + 146     13 QuartzCore 0x000000011506be70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366     14 QuartzCore 0x000000011506bcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24     15 QuartzCore 0x0000000115060475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277     16 QuartzCore 0x000000011508dc0a _ZN2CA11Transaction6commitEv + 486     17 UIKit 0x00000001101ddb47 _afterCACommitHandler + 174     18 CoreFoundation 0x0000000111b8b367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23     19 CoreFoundation 0x0000000111b8b2d7 __CFRunLoopDoObservers + 391     20 CoreFoundation 0x0000000111b80f2b __CFRunLoopRun + 1147     21 CoreFoundation 0x0000000111b80828 CFRunLoopRunSpecific + 488     22 GraphicsServices 0x0000000114b2aad2 GSEventRunModal + 161     23 UIKit 0x00000001101b2610 UIApplicationMain + 171     24 TableView 0x000000010f94855f main + 111     25 libdyld.dylib 0x00000001126f292d start + 1 ) libc ++ abi.dylib:以NSException类型的未捕获异常终止 (lldb)

1 个答案:

答案 0 :(得分:1)

正如其他人所提到的(并且你的输出明确指出)你的NSArray是空的。如果您尝试从不存在的NSArray引用索引,则每次都会崩溃。

显然您正在尝试访问索引0处的对象。您可以错误地检查数组是否至少包含项目数作为索引号:

NSArray *myArray = [NSArray arrayWithObject:@"foo"];

int indexDesired = 0; //since you were attempting to access index 0
long indexCount = [myArray count];

if (indexCount > indexDesired) { //check to make sure index exists
    id myObject = [myArray objectAtIndex:indexDesired];
}