因 [__NSArrayM objectAtIndex:] 崩溃:索引 0 超出空数组错误范围

发布于 2024-12-11 05:56:26 字数 1909 浏览 0 评论 0 原文

我通过 iOS 应用程序的用户收到崩溃报告,但我无法重现崩溃,也无法将错误追溯到我自己的代码中的一行(除了它源自 main.m 中的第 14 行,但这是iOS 应用程序的默认应用程序创建。在我收到的崩溃报告下面,

我知道在某个时刻,正在从空数组中检索一个对象,但由于它似乎没有指向我自己的代码,这可能是 iOS 中的一个错误吗?(确实如此)在不同的平台和不同的 iOS 版本上)

我希望有人知道发生了什么或者可以为我指明正确的方向。 谢谢。

崩溃报告:

Incident Identifier: [TODO]
CrashReporter Key:   [TODO]
Process:         Mary Black [797]
Path:            /var/mobile/Applications/28A68F8B-294E-4B86-9E75-ED5484E5EF4D/Mary Black.app/Mary Black
Identifier:      net.broset.Mary-Black
Version:         225
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2011-10-14 03:47:32 +0000
OS Version:      iPhone OS 5.0 (9A334)
Report Version:  104

Exception Type:  SIGTRAP
Exception Codes: #0 at 0x35b07848
Crashed Thread:  0

Application Specific Information:
*** Terminating app due to uncaught exception \\\'NSRangeException\\\', reason: \\\'*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array\\\'

Thread 0 Crashed:
0   libsystem_kernel.dylib              0x00010848 __kill + 8
1   CoreFoundation                      0x000b9987 __handleUncaughtException + 75
2   libobjc.A.dylib                     0x000092d1 _objc_terminate + 129
3   libc++abi.dylib                     0x000043c5 _ZL19safe_handler_callerPFvvE + 77
4   libc++abi.dylib                     0x00004451 operator delete(void*) + 1
5   libc++abi.dylib                     0x00005825 __cxa_current_exception_type + 1
6   libobjc.A.dylib                     0x00009235 objc_exception_rethrow + 13
7   CoreFoundation                      0x0000f545 CFRunLoopRunSpecific + 405
8   CoreFoundation                      0x0000f3a5 CFRunLoopRunInMode + 105
9   GraphicsServices                    0x00003fed GSEventRunModal + 157
10  UIKit                               0x00031743 UIApplicationMain + 1091
11  Mary Black                          0x00002fa7 main (main.m:14)

I am getting crash reports via users of my iOS app, but crash I can't reproduce myself, nor can I trace the error back to a line in my own code (except that it originates from line 14 in main.m but this is the default application creation of iOS apps. Below the a crash report I received.

In understand that at some point a object is at index 0 is being retrieved from an empty Array. But since it doesn't seem to point to my own code, can it be a bug in iOS? (It happens on different platforms and with different iOS versions).

I hope someone has an idea what is happening or can point me in the right direction.
Thanks.

CRASH REPORT:

Incident Identifier: [TODO]
CrashReporter Key:   [TODO]
Process:         Mary Black [797]
Path:            /var/mobile/Applications/28A68F8B-294E-4B86-9E75-ED5484E5EF4D/Mary Black.app/Mary Black
Identifier:      net.broset.Mary-Black
Version:         225
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2011-10-14 03:47:32 +0000
OS Version:      iPhone OS 5.0 (9A334)
Report Version:  104

Exception Type:  SIGTRAP
Exception Codes: #0 at 0x35b07848
Crashed Thread:  0

Application Specific Information:
*** Terminating app due to uncaught exception \\\'NSRangeException\\\', reason: \\\'*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array\\\'

Thread 0 Crashed:
0   libsystem_kernel.dylib              0x00010848 __kill + 8
1   CoreFoundation                      0x000b9987 __handleUncaughtException + 75
2   libobjc.A.dylib                     0x000092d1 _objc_terminate + 129
3   libc++abi.dylib                     0x000043c5 _ZL19safe_handler_callerPFvvE + 77
4   libc++abi.dylib                     0x00004451 operator delete(void*) + 1
5   libc++abi.dylib                     0x00005825 __cxa_current_exception_type + 1
6   libobjc.A.dylib                     0x00009235 objc_exception_rethrow + 13
7   CoreFoundation                      0x0000f545 CFRunLoopRunSpecific + 405
8   CoreFoundation                      0x0000f3a5 CFRunLoopRunInMode + 105
9   GraphicsServices                    0x00003fed GSEventRunModal + 157
10  UIKit                               0x00031743 UIApplicationMain + 1091
11  Mary Black                          0x00002fa7 main (main.m:14)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寂寞花火° 2024-12-18 05:56:26

调试此问题的一种方法是在 objectAtIndex: 上添加符号断点:这可能会导致在调试器命中您要查找的目标之前多次命中 objectAtIndex:,但保证能找到它。

Xcode 4 中的步骤:

  • 查看 >导航器>断点导航器
  • 弹出窗口中选择“添加符号断点”
  • 单击“+”,然后在“符号”文本字段中的“objectAtIndex:”

,然后单击“运行时完成”,如果您无法分辨正在点击哪个 objectAtIndex:,请移动滑块在调试导航器的底部一直到右侧。

One way to debug this issue is to add a Symbolic Breakpoint on objectAtIndex: This may result in many hits to objectAtIndex: before the debugger hits the one you're after but it's guaranteed to find it.

Steps in Xcode 4:

  • View > Navigators > Breakpoint Navigator
  • click '+' and choose Add Symbolic Breakpoint in the pop-up
  • type in "objectAtIndex:" in the Symbol text field and click Done

at runtime, if you can't tell which objectAtIndex: you're hitting, move the slider at the bottom of the Debug Navigator all the way to the right.

初吻给了烟 2024-12-18 05:56:26

这会将调试器停止在有问题的行:

Xcode/Edit Scheme/Diagnostics/Log Exceptions。

This will stop the debugger at the offending line:

Xcode/Edit Scheme/Diagnostics/Log Exceptions.

木森分化 2024-12-18 05:56:26

此错误意味着您尝试从 NSArray 中未找到对象的位置获取对象。换句话说:如果索引为 0,则数组为空。
而且很可能是您的代码,因为 main() 调用您的代码。

This error means, that you try to get an object from a NSArray from a position where no object is found. In other words: if the index is 0, than your array is empty.
And most likely it is your code, as main() invokes your code.

時窥 2024-12-18 05:56:26

您需要在项目中搜索 objectAtIndex: 的所有用法,并排除每一个罪魁祸首。确保您永远不会在空数组上调用它。

另一个提示:如果您知道只想获取数组中的最后一个对象,或者您知道数组只会包含一个对象,则可以使用 lastObject 而不是objectAtIndex:——它更安全,因为它不会抛出异常,尽管您仍然需要检查nil

You need to search your project for all usages of objectAtIndex: and rule out each one as the culprit. Make sure you are never calling it on an empty array.

Another tip: If you know you only want to get the last object in an array, or you know the array will only ever contain one object, you can use lastObject instead of objectAtIndex: -- it's safer because it won't throw an exception, though you still need to check for nil.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文