__NSArrayM 索引越界
__NSArrayM index beyond bounds
很抱歉发帖,因为类似的问题已经被问过很多次了。
我继承了 Objective C 中的一个 iOS 应用程序,需要对其进行修改。最初它在 Xcode 的旧版本中运行良好。然后我更新了我的 Xcode 然后它 运行 在下面的方法中变成了数组索引越界的未捕获异常。
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MartialArtsAppDelegate class]));
}
}
转储堆栈表明在 CoreFoundation 框架的深处,
超出范围 [0..1] 的 NSMutableArray 有一个索引 3。
我不确定那是什么意思。我看不到它是哪个数组。
此外,我没有看到我在应用程序中的何处声明了 NSMutableArray。
转储堆栈如下。非常感谢您的协助。
2016-03-16 19:54:56.522 HanDynastyMartialArts[480:5616] WARNING: A Gesture recognizer (<UISwipeGestureRecognizer: 0x7ff9fa596790; state = Possible; view = <UIView 0x7ff9fa599c10>; target= <(action=upSwipeGesture:, target=<MartialArtsViewController 0x7ff9fb04ea00>)>; direction = up>) was setup in a storyboard/xib to be added to more than one view (-><UIView: 0x7ff9fa5af170; frame = (0 0; 320 450); autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7ff9fa5d77b0>; layer = <CALayer: 0x7ff9fa5af2d0>>) at a time, this was never allowed, and is now enforced. Beginning with iOS 9.0 it will be put in the first view it is loaded into.
2016-03-16 19:54:56.587 HanDynastyMartialArts[480:5616] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 3 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106658f65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001060d2deb objc_exception_throw + 48
2 CoreFoundation 0x000000010651ff55 -[__NSArrayM insertObject:atIndex:] + 901
3 Foundation 0x0000000105b11a11 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 106
4 CoreFoundation 0x0000000106574432 -[NSMutableArray insertObjects:count:atIndex:] + 162
5 CoreFoundation 0x000000010657419f -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 335
6 CoreFoundation 0x0000000106574023 -[NSMutableArray addObjectsFromArray:] + 723
7 UIKit 0x0000000104c2e49f -[UIRuntimeOutletCollectionConnection performConnect] + 860
8 CoreFoundation 0x0000000106599b10 -[NSArray makeObjectsPerformSelector:] + 224
9 UIKit 0x0000000104967306 -[UINib instantiateWithOwner:options:] + 1864
10 UIKit 0x000000010475284d -[UIViewController _loadViewFromNibNamed:bundle:] + 381
11 UIKit 0x0000000104753179 -[UIViewController loadView] + 178
12 UIKit 0x000000010475347c -[UIViewController loadViewIfRequired] + 139
13 UIKit 0x0000000104796c26 -[UINavigationController _layoutViewController:] + 54
14 UIKit 0x00000001047974dd -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 433
15 UIKit 0x0000000104797633 -[UINavigationController _startTransition:fromViewController:toViewController:] + 116
16 UIKit 0x0000000104798879 -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
17 UIKit 0x000000010479967d -[UINavigationController __viewWillLayoutSubviews] + 57
18 UIKit 0x000000010493163d -[UILayoutContainerView layoutSubviews] + 248
19 UIKit 0x000000010467911c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
20 QuartzCore 0x000000010a55536a -[CALayer layoutSublayers] + 146
21 QuartzCore 0x000000010a549bd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
22 QuartzCore 0x000000010a549a4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
23 QuartzCore 0x000000010a53e1d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
24 QuartzCore 0x000000010a56b9f0 _ZN2CA11Transaction6commitEv + 508
25 QuartzCore 0x000000010a56c154 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
26 CoreFoundation 0x00000001065849d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
27 CoreFoundation 0x0000000106584947 __CFRunLoopDoObservers + 391
28 CoreFoundation 0x0000000106579ebc CFRunLoopRunSpecific + 524
29 UIKit 0x00000001045c398d -[UIApplication _run] + 402
30 UIKit 0x00000001045c8676 UIApplicationMain + 171
31 HanDynastyMartialArts 0x00000001042b3cbf main + 111
32 libdyld.dylib 0x0000000106fae92d start + 1
33 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
要查看导致错误的实际语句,请添加异常断点:
- 从主菜单Debug:Breakpoints:Create异常断点。
- 右键单击断点并将异常设置为Objective-C。
- 添加一个动作:“po $arg1”。
运行 获取断点的应用程序,您将位于导致异常的行,错误消息将出现在调试器控制台中。
Breakpoint example:
很抱歉发帖,因为类似的问题已经被问过很多次了。
我继承了 Objective C 中的一个 iOS 应用程序,需要对其进行修改。最初它在 Xcode 的旧版本中运行良好。然后我更新了我的 Xcode 然后它 运行 在下面的方法中变成了数组索引越界的未捕获异常。
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MartialArtsAppDelegate class]));
}
}
转储堆栈表明在 CoreFoundation 框架的深处, 超出范围 [0..1] 的 NSMutableArray 有一个索引 3。 我不确定那是什么意思。我看不到它是哪个数组。
此外,我没有看到我在应用程序中的何处声明了 NSMutableArray。 转储堆栈如下。非常感谢您的协助。
2016-03-16 19:54:56.522 HanDynastyMartialArts[480:5616] WARNING: A Gesture recognizer (<UISwipeGestureRecognizer: 0x7ff9fa596790; state = Possible; view = <UIView 0x7ff9fa599c10>; target= <(action=upSwipeGesture:, target=<MartialArtsViewController 0x7ff9fb04ea00>)>; direction = up>) was setup in a storyboard/xib to be added to more than one view (-><UIView: 0x7ff9fa5af170; frame = (0 0; 320 450); autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7ff9fa5d77b0>; layer = <CALayer: 0x7ff9fa5af2d0>>) at a time, this was never allowed, and is now enforced. Beginning with iOS 9.0 it will be put in the first view it is loaded into.
2016-03-16 19:54:56.587 HanDynastyMartialArts[480:5616] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 3 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106658f65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001060d2deb objc_exception_throw + 48
2 CoreFoundation 0x000000010651ff55 -[__NSArrayM insertObject:atIndex:] + 901
3 Foundation 0x0000000105b11a11 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 106
4 CoreFoundation 0x0000000106574432 -[NSMutableArray insertObjects:count:atIndex:] + 162
5 CoreFoundation 0x000000010657419f -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 335
6 CoreFoundation 0x0000000106574023 -[NSMutableArray addObjectsFromArray:] + 723
7 UIKit 0x0000000104c2e49f -[UIRuntimeOutletCollectionConnection performConnect] + 860
8 CoreFoundation 0x0000000106599b10 -[NSArray makeObjectsPerformSelector:] + 224
9 UIKit 0x0000000104967306 -[UINib instantiateWithOwner:options:] + 1864
10 UIKit 0x000000010475284d -[UIViewController _loadViewFromNibNamed:bundle:] + 381
11 UIKit 0x0000000104753179 -[UIViewController loadView] + 178
12 UIKit 0x000000010475347c -[UIViewController loadViewIfRequired] + 139
13 UIKit 0x0000000104796c26 -[UINavigationController _layoutViewController:] + 54
14 UIKit 0x00000001047974dd -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 433
15 UIKit 0x0000000104797633 -[UINavigationController _startTransition:fromViewController:toViewController:] + 116
16 UIKit 0x0000000104798879 -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
17 UIKit 0x000000010479967d -[UINavigationController __viewWillLayoutSubviews] + 57
18 UIKit 0x000000010493163d -[UILayoutContainerView layoutSubviews] + 248
19 UIKit 0x000000010467911c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
20 QuartzCore 0x000000010a55536a -[CALayer layoutSublayers] + 146
21 QuartzCore 0x000000010a549bd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
22 QuartzCore 0x000000010a549a4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
23 QuartzCore 0x000000010a53e1d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
24 QuartzCore 0x000000010a56b9f0 _ZN2CA11Transaction6commitEv + 508
25 QuartzCore 0x000000010a56c154 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
26 CoreFoundation 0x00000001065849d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
27 CoreFoundation 0x0000000106584947 __CFRunLoopDoObservers + 391
28 CoreFoundation 0x0000000106579ebc CFRunLoopRunSpecific + 524
29 UIKit 0x00000001045c398d -[UIApplication _run] + 402
30 UIKit 0x00000001045c8676 UIApplicationMain + 171
31 HanDynastyMartialArts 0x00000001042b3cbf main + 111
32 libdyld.dylib 0x0000000106fae92d start + 1
33 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
要查看导致错误的实际语句,请添加异常断点:
- 从主菜单Debug:Breakpoints:Create异常断点。
- 右键单击断点并将异常设置为Objective-C。
- 添加一个动作:“po $arg1”。
运行 获取断点的应用程序,您将位于导致异常的行,错误消息将出现在调试器控制台中。
Breakpoint example: