Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:] - ios

I am trying to run app on the iphone 6 and I get this error. I get the error after making the facebook login. Normally, it is working successfully on the simulator. I couldn't find why it gives the error.
Error:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray'
*** First throw call stack:
(0x181dcae38 0x18142ff80 0x181d41a6c 0x100418620 0x100417aa0 0x10042dbac 0x10006a3a0 0x10006aa0c 0x186f14b40 0x186f14744 0x1872ba9fc 0x1872774f4 0x187273f04 0x1871c6fd8 0x1871d4990 0x186f064a4 0x181d807b0 0x181d7e554 0x181d7e984 0x181ca8d10 0x183590088 0x186f7df70 0x10008810c 0x1818468b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

Since you posted no stack trace, I assume you want to learn how to find bugs like this. First, in Xcode, set a breakpoint on Objective-C exceptions, so you find where exactly the crash happens.
The error says clearly that you are trying to access array [0] for an NSArray that is empty. Once you find the location of the crash that should be easy to find.

Related

iOS app termination due to uncaught error

This is the exception and in my ignorance of using the tools in the IDE I have a very basic question. How do I go to the line of code that causes the issue? I have located where the issue is, but rather than NSLogging a message in the didload and didAppear events, then stepping through the code until is breaks seems like a long way to figure this out. I am assuming that the [5970:1623718] is a clue, but to what?
2017-10-04 08:22:47.798 Auto Mileage - Universal[5970:1623718] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]'
*** First throw call stack:
(0x2580f91b 0x24faae17 0x2572172b 0xd89e3 0xd9e57 0x2a0d1465 0x2a0d15a5 0x2a0c0b51 0x2a0d5d1b 0x29e7523b 0x29d86a73 0x27e1ebcd 0x27e1a375 0x27e1a209 0x27e196d1 0x27e193a5 0x29d7db79 0x257d16c9 0x257cf9cd 0x257cfdff 0x2571f229 0x2571f015 0x26d0fac9 0x29df3189 0xe9159 0x253c7873)
libc++abi.dylib: terminating with uncaught exception of type NSException
You can add an "Exception Breakpoint".
Like in the picture, select "Show the Breakpoint navigator" (the blue icon on the top of the navigator), then click on the plus icon on the bottom and click on "Add Exception Breakpoint".

how to know which NSArray is causing the exception

My iOS app is crashing with the following error message. Basically, I am trying to access an array index that is not present.
How do I get Xcode to show me the exact array name on which I did the wrong operation (or the call stack leading up the crash)?
****Error message I see***
2015-11-05 09:24:38.509 firstCDapp[1165:734714] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray'
*** First throw call stack:
(0x279c585b 0x39086dff 0x27958bdf 0x923f9 0x2be38d63 0x2be38e89 0x2be28df5 0x2be3d46f 0x2bbe35af 0x2baf5cc3 0x2b3bdb05 0x2b3b9201 0x2b3b9091 0x2b3b85b1 0x2b3b8263 0x2b3b1a1f 0x27988091 0x27986387 0x279867c5 0x278d90d9 0x278d8ecd 0x30c4eaf9 0x2bb622dd 0x93b35 0x397d4873)
libc++abi.dylib: terminating with uncaught exception of type NSException
Try to add an Exception Breakpoint -> right click -> edit -> Exception = Obj-c, this can help you to find the error

NSRangeException error - In-App-Purchase implemantaition

I've implemented an In-App-Purchase into my app.
If I run my app and press the "purchase" button, i get the following error:
2014-10-22 17:48:20.733 MyApp[170:3435] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
Does someone got the same error and know what's to do?
It is the typical exception that emerges when handling an empty array.
Add an exception breakpoint to your project in Xcode, as shown in the picture.
It will stop the execution of the app in the line that the exception does happen

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'

When I run this code it says that :
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
I think that the problem is that, it tries to fetch the info from here : http://maps.googleapis.com/maps/api/directions/json? but it is not able to perform that action due to the non availability of the parameters : origin=LosAngeles&destination=Texas&sensor=false
The question :
How to make *jsonURL attached (concatenated with) to *post, in order to obtain the full link in the background and process it : http://maps.googleapis.com/maps/api/directions/json?origin=LosAngeles&destination=Texas&sensor=false
but keeping the same structure (divided in that way).
In order to have the parameters be part of the URL, you need to have the parameters be part of the string you pass to URLWithString:.

Resolving Beyond Bounds Error in iOS

An app I'm working is crashing due to an out of bounds error - I should be able to figure out why however the output console does not show which array in the code is causing the crash - does anyone have any ideas on how I can find out.
2013-09-17 11:14:15.639 TestApp[5970:11303]
*** Terminating app due to uncaught exception 'NSRangeException',
reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
Thanks

Resources