-5

Well, I know the cause of the error, my question here is how to avoid this kind of error. In my case, what I want is, if the user enters a wrong id which means when the array return 0 results, is says for example :

NSLog (@"The id you entered is false !");

else, it proceeds the code normally without crashing.

Any ideas on how I can solve it ?

Al_fareS
  • 725
  • 1
  • 9
  • 18
  • a bit hard to 'help' you if you don't even show us the crashing code :)) – Daij-Djan Feb 09 '14 at 18:51
  • you still don't show where you access the array – Daij-Djan Feb 09 '14 at 19:22
  • it access to the array which is inside the link using : `NSDictionary *routes = [dataDictionary objectForKey:@"routes"][0];` – Al_fareS Feb 09 '14 at 19:30
  • I have answered here..http://stackoverflow.com/questions/12641051/ios-error-nsarrayi-objectatindex-index-1-beyond-bounds-0-0/30916210#30916210 May be helpful for someone. – Narasimha Nallamsetty Jun 18 '15 at 13:16
  • Possible duplicate of [IOS App crash: \[\_\_NSArrayI objectAtIndex:\]: index 0 beyond bounds for empty array](http://stackoverflow.com/questions/27243024/ios-app-crash-nsarrayi-objectatindex-index-0-beyond-bounds-for-empty-arra) – NSNoob Dec 09 '16 at 10:37

1 Answers1

1
id array = [dataDictionary objectForKey:@"routes"];
if([array count] == 0) {
    NSLog(@"don't access it as the index is out of bounds);
    return;
}
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135