Please help me out with this exception - iphone

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
In my TableViewController I am loading list of arrays..... with selected its display's its detailedViewController...
When I get back and selected the same index or another index i get this exception NSRangeException...
I dont know what to do ?
Can any one help me out.

The array is empty at that point. A good idea is, add some lines of code like this:
NSLog(#"\n\n here, there are this many items: %d \n\n", [yourArrayName count]);
put that line in everywhere possible, add it in at least ten places.
Open your console ("Run" menu in XCode).
You'll soon figure out what is going wrong! hope it helps.

Related

Sphero AR Example Crashes Randomly

I'm testing the Sphero-AR-SDK found on GitHub (https://github.com/orbotix/Sphero-AR-SDK)
When testing, I seem to have random crashes on connect.
The issue I'm trying to debug is an index out of range error.
*"*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x325102a3 0x3a22d97f 0x3245bb75 0x8cb42b 0x32e270f5 0x324e5683 0x324e4ee9 0x324e3cb7 0x32456ebd 0x32456d49 0x3602d2eb 0x3436c301 0x7f10 0x3188)
libc++abi.dylib: terminate called throwing an exception"*
This happens a fair amount when booting the application but not all the time (sometimes it will get through and play the game).
I was wondering if anyone else was having issues with these random crashes or have I not set it up correctly?
I've had a look at the "Other Linker Flags" in XCode too and it has -all_load.
Also, I've safely checked the only place where I could find an array object access in the .mm files (RKUNBridge.mm) has this line:
[RKDeviceSensorsData *data = [sensors_data.dataFrames objectAtIndex:0];
And I safely checked this array exists and is greater than one to double check it's not this line.
Any ideas or suggestions would be much appreciated.
Thanks for reading.

Thread 1: signal SIGABRT xcode 4.4 ios 5.1 objective-c HELP >.<

Ok so yesterday I had some trouble with this error, turned out I just needed to be patient and read through more of the book. This time I have got to the end of the project and I am getting this error at a different point.
I have isolated the line of code causing the issue but I'm not sure what the issue is!
htmlString=[htmlString stringByAppendingString: appDelegate.savedNumber];
Debug console is saying:
2012-08-09 13:06:47.235 tester[1357:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSCFConstantString stringByAppendingString:]: nil argument'
*** First throw call stack:
(0x14b3022 0xeb3cd6 0x145ba48 0x145b9b9 0x941b92 0x29bd 0xdda1e 0x3c401 0x3c670 0x3c836 0x4372a 0x24c2 0x14386 0x15274 0x24183 0x24c38 0x18634 0x139def5 0x1487195 0x13ebff2 0x13ea8da 0x13e9d84 0x13e9c9b 0x14c65 0x16626 0x20e2 0x2055)
terminate called throwing an exception
Anyone have any ideas? :)
It is because appDelegate.savedNumber is nil (does not set) . And why it is nil this is another question.
Looks like exactly what's written, you're passing nil argument to the method. Check if your savedNumber is a valid string object.

NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' when presenting view controller

I have developed an app that in testing has worked fine but when it has could live I have had some issues with crashes when presenting Modal View Controllers. The issue is in here some where:
NSLog(#"Looks like we made it here 1");
UIViewController *mtaViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"mtaViewController"];
NSLog(#"Looks like we made it here 2");
[mtaViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
NSLog(#"Looks like we made it here 3");
[self presentModalViewController:mtaViewController animated:YES];
NSLog(#"Looks like we made it here 4");
and my output to the console is:
2012-06-14 09:26:24.161 appname[2013:707] Looks like we made it here 1
2012-06-14 09:26:24.165 appname[2013:707] Looks like we made it here 2
2012-06-14 09:26:24.166 appname[2013:707] Looks like we made it here 3
2012-06-14 09:26:28.866 appname[2013:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x343ac8bf 0x345fc1e5 0x342f5b6b 0x6d3fd 0x6e719 0x3778e7ff 0x37798d53 0x37798cc1 0x37838339 0x3783714f 0x37891d97 0x7ce1d 0x7cd47 0x3788eaa5 0x3776a81b 0x3776ffb9 0x34ec1ba7 0x36fe0e8d 0x3437f2dd 0x343024dd 0x343023a5 0x30b86fcd 0x37783743 0x84327 0x6b468)
terminate called throwing an exception
I have set up in a function that I call when wanting to change view controllers and as you can see it makes it all the way down to "Looks like we made it here 3" so I suspect that there is an issue with line
[self presentModalViewController:mtaViewController animated:YES];
Can anyone help?
Check any array in mtaViewController, I dont see any array in your code so I'm thinking the issue is within mtaViewController. :)
Are you sure you view controller really gets initialized? Just an idea but this line
[mtaViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
would do nothing if mtaViewController would be nil. In Cocoa you can send messages to nil without problems. Your app only will crash later when you try to do something specific with them. Does
NSLog(#"%#", mtaViewController);
tell you something useful? Please make also sure you connected everything in IB that has to be connected (if you aren't working everything out in raw code).
By the way. This is deprecated. Use
presentViewController:animated:completion:
instead.

Finding out source of nsrangeexception

I have an NSRangeException error that does not occur all the time(especially when I am debugging). It comes up randomly, and I am unable to figure out where it is coming from. I have lots of array manipulation, so its difficult to eliminate it that way.
My question is whether I can get a clue , for example class and line number from the debugger output, for example what are the numbers 12109 and 707?:
2012-03-15 09:25:15.303 appname[12109:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 0]'
Any pointers appreciated.
Edit:
Remaining part of the log:
*** First throw call stack:
(0x33ff38bf 0x342431e5 0x33f4b275 0x1702d 0x37662331 0x3761b2b3 0x33f4d435 0x373b79eb 0x373b79a7 0x373b7985 0x373b76f5 0x3744de55 0x374e3e45 0x373aa99b 0x33fc7b4b 0x33fc5d87 0x33fc60e1 0x33f494dd 0x33f493a5 0x307cdfcd 0x373ca743 0x2325 0x22e4)
terminate called throwing an exception
Add an Exception breakpoint. This will stop on the line that raises the exception.
In the breakpoints navigator, click the plus in the bottom left, choose exception breakpoint, and all exceptions. You should have this on all projects really, it is invaluable. We'd have far fewer questions here, though!
Look further down in your crash log, and chances are that at some point it will point to an actual method and line.
For e.g. in the below block from a device crash log, the last line clearly points to the request:didLoad: method in the FacebookController.m class at line 264.
0x33defacb -[NSObject doesNotRecognizeSelector:] + 175
0x33dee945 ___forwarding___ + 301
0x33d49680 _CF_forwarding_prep_0 + 48
0x00037e47 -[FacebookController request:didLoad:] (FacebookController.m:264)

issue with array

Getting error in this line :
NSString *nmm =[narr objectAtIndex:1];
error shows :
'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index
(1) beyond bounds (1)'
It looks like your array only got one value (which you can accesss at index 0, not index 1).
You should probably start by checking the contents of narr at run time. It sounds like the contents aren't what you would expect them to be at the desired point in execution. Right before the line you posted in your question, use an NSLog call to log the contents of the array like this:
NSLog(#"Contents of array: %#", narr);
Then run the app and check the console after the error arises. Put some time into learning how to use NSLog, breakpoints, and the GDB console - they will end up saving you lots of frustration when debugging.
Your comments on unset's answer raise another point: Why are you storing multiple pieces of data inside the same string? Wouldn't it be easier to separate name, lname and id into separate strings and place each into its own array cell? Then you could access them using [narr objectAtIndex:] without having to worry about parsing the string every time you need one of those pieces of information.