Reputation: 3472
I know this question has been asked several times, but Im looking for a more general answer. I have developed an app for iOS 6, I tested it on simulator(Retina 3.5 and 4 inch) and also on an iPhone 4 device. It has never crashed but when I submitted the app to Apple and they answered with:
We found that your app crashed upon launch on iPhone 5 running iOS 6.1.3,
Looking at the crash log
We see that it crashes in line 164 from a index out of bounds, which makes sense because I have this code there:
I added that "if" to stop the execution whenever the indexTimesArray
was bigger than the length of the array and see why that happened, but I was unable to reproduce the error. I never get an index out of bounds
as they do...
It's true that I haven't test it on a iPhone 5 device, but I have XCode 4.6 and iOS 6.1 on my computer, and also a iPhone 4 with iOS 6.1.3, but it's also true that the guys at Apple are getting the app crashed, so how to reproduce the error?
I tried to install the app from TestFlight because it installs it as a brand new app, just like they do when they test it, but still no errors...
How can I reproduce the error? Could it be a problem with th build settings?
Thanks
[EDIT] I initialize the contents of timesArray in the init method of the object, like this:
- (id)init{ self = [super init]; df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd HH:mm"]; rangeDates = [[NSArray alloc]initWithObjects:@"2013-04-11 10:00", @"2013-04-12 10:00", @"2013-04-13 10:00", @"2013-04-14 10:00", nil]; timesArray = [[NSArray alloc]initWithArray:[NSArray arrayWithObjects:@"10:00", @"11:00", @"12:00", @"13:00", @"14:00", @"15:00", @"16:00", @"17:00", @"18:00", @"19:00", @"20:00", @"21:00", @"22:00", nil]]; colorDictio = [[NSDictionary alloc]initWithObjects:[NSArray arrayWithObjects:[UIColor colorWithRed:0.74 green:0.66 blue:0.37 alpha:1.0], [UIColor colorWithRed:0.64 green:0.15 blue:0.11 alpha:1.0], [UIColor colorWithRed:0.313 green:0.65 blue:0.69 alpha:1.0], [UIColor colorWithRed:0.79 green:0.4 blue:0.59 alpha:1.0], [UIColor colorWithRed:0.45 green:0.55 blue:0.53 alpha:1.0], [UIColor colorWithRed:0.14 green:0.27 blue:0.66 alpha:1.0], nil] forKeys:[NSArray arrayWithObjects:@"showers area", @"zinctalks", @"zincnetwork", @"zincshows", @"zinclabs", @"zinczone", nil] ]; return self; }
Upvotes: 1
Views: 516
Reputation: 3472
Thanks to @mayur, his comment is the right answer, "I had faced a similar error earlier with arrays in Objective-C... My suggestion would be to use self with NSMutableArrays or NSArrays"
Upvotes: 0
Reputation: 90117
To figure out how to reproduce that error you have to look at the code where you create timesArray.
The out of bounds error happens because [timesArray count]
is less than 2 (or the whole array is nil). So you have to figure out which condition leads to an array with one or zero objects. Maybe it happens because there is no internet connection.
It's always a good idea to wrap objectAtIndex: in a check for the actual size of the array.
I would replace else {
with else if ([timesArray count] >= 2) {
and add an additional else that handles <2 arrays.
Upvotes: 1
Reputation: 4500
First of all this is not a OS related error. Your app is crashing because the wrong index of array is being accessed.
To debug the error what you can do is try to print the value of indexTimesArray before the if. Also, try to print all the values you are passing to access the array element. Which will help you track the wrong index which is being sent.
Upvotes: 0