當我第一次運行應用程序時,它工作正常。但是當我再次運行兩次兩次,它崩潰。NSRangeException',原因:'*** - [__ NSArrayM objectAtIndex:]:索引5超出空數組的範圍'
這是錯誤..
NSRangeException」,原因: '*** - [__ NSArrayM objectAtIndex:]:索引5超出界限爲空數組'
當我第一次運行應用程序時,它工作正常。但是當我再次運行兩次兩次,它崩潰。NSRangeException',原因:'*** - [__ NSArrayM objectAtIndex:]:索引5超出空數組的範圍'
這是錯誤..
NSRangeException」,原因: '*** - [__ NSArrayM objectAtIndex:]:索引5超出界限爲空數組'
原因:您正在訪問空數組即將訪問索引處的對象。
與
//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! **
你的數組是空的,但你試圖訪問它中的一個對象。那就是問題所在。
原因更換像所有的地方在你的代碼下面
[arrMydata objectAtIndex:indexPath.row];
:根據你的日誌,你要訪問空數組。只需通過以下代碼修復此問題
if (arrMydata.count > inxexPath.row)
sharObj = [arrMydata objectAtIndex:indexPath.row]
'arrMydata'數組似乎是空的。那就是崩潰日誌所告訴的。 – GoodSp33d
arrMydata應該分配] init'ed或者它應該有arrayWithCapacity:// somevalue之前添加對象到arrMydata –
@ 2-Stroker我知道,但我找不到解決方案。 –