Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds for empty array'

in my application when i run app for first time,it work ok.but when i run again 2 two times, it crashes.

This is the error..

NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds for empty array'

enter image description here

enter image description here

like image 845
Rushi trivedi Avatar asked May 02 '14 08:05

Rushi trivedi


2 Answers

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! **

like image 147
Vijay-Apple-Dev.blogspot.com Avatar answered Nov 15 '22 20:11

Vijay-Apple-Dev.blogspot.com


You array is empty, but you're trying to access an object in it. That is the problem.

like image 31
Chuck Avatar answered Nov 15 '22 20:11

Chuck