I have a problem with my app, which run well on the simulator but when I launch on my iDevice I got an error:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'
0 CoreFoundation 0x3513cfd3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x303928a5 objc_exception_throw + 24
2 CoreFoundation 0x350bff99 -[__NSArrayM insertObject:atIndex:] + 472
3 CoreFoundation 0x350bfda7 -[__NSArrayM addObject:] + 34
....
Program received signal: “SIGABRT”.
In the debugger I can see where is the problem. The error comes from there, at the addObject:
for (int i = 0; i < [arrayValues count]; i++) {
f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
myNumber =[f numberFromString:[arrayValues objectAtIndex:i]];
[arrayValues2 addObject:myNumber];
[f release]; }
Here I convert objects of arrayValues (NSString) in NSNumbers in arrayValues2.
In the Simulator there is no problem, the arrays are not empties.
I don’t know where to look for.
I also checked the other posts of stackoverflow, they are not really like my error
well… I’m not sure what your problem is, but there is a much better way to do this…
which may help because you won’t be outstepping any array boundaries, or inserting any nil objects.
If you want some more help you’re going to have to NSLog arrayValues and give us the output so we can see what you’re dealing with. 🙂