ios NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]:索引 5 超出空数组的边界'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23423473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds for empty array'
提问by Rushi trivedi
in my application when i run app for first time,it work ok.but when i run again 2 two times, it crashes.
在我的应用程序中,当我第一次运行应用程序时,它工作正常。但是当我再次运行 2 次时,它崩溃了。
This is the error..
这是错误..
NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds for empty array'
NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]:索引 5 超出空数组的边界'
回答by Vijay-Apple-Dev.blogspot.com
Reason:You are accessing Empty array about to access object at index.
原因:您正在访问即将访问索引处的对象的空数组。
replace all places like in your code below
替换下面代码中的所有位置
[arrMydata objectAtIndex:indexPath.row];
with
和
//1. Positive index ([anArray objectAtIndex:-NUMBERS]) will crash
//2. within the array boundary
if([arrMydata count] > 0 && [arrMydata count] > indexPath.row){
shrObj=[arrMydata objectAtIndex:indexPath.row];
}
else{
//Array is empty,handle as you needed
}
**Here You can see the non software example, which will explain this issue. Good luck! **
回答by Chuck
You array is empty, but you're trying to access an object in it. That is the problem.
您的数组为空,但您正在尝试访问其中的对象。那就是问题所在。
回答by Mani
Reason:According to your log, you're trying to access empty array. Just fix this by below code
原因:根据您的日志,您正在尝试访问空数组。只需通过以下代码修复此问题
if (arrMydata.count > inxexPath.row)
sharObj = [arrMydata objectAtIndex:indexPath.row]
回答by Apneist
In case this helps someone : in my case the array was not in code, but an IB outlet that was an array of 5 UIImageViews in the storyboard.
如果这对某人有帮助:在我的情况下,数组不在代码中,而是一个 IB 插座,它是故事板中 5 个 UIImageViews 的数组。
@IBOutlet var upAndDownArrowImages: [UIImageView]!
@IBOutlet var upAndDownArrowImages:[UIImageView]!
Reason for the crash was that I mistakenly deleted 1 of those UIImageViews from the Storyboard.
崩溃的原因是我错误地从 Storyboard 中删除了其中 1 个 UIImageViews。
回答by srsstyle
In my case, it Crashes for heightForRowAt indexpath
, Do check this method for smooth operation.
在我的情况下,它崩溃了heightForRowAt indexpath
,请检查此方法以确保顺利运行。
Hope it Helps someone.
希望它可以帮助某人。