2

After inheirting an iPhone app project I'm tasked with the debugging of it after an update. Not an objective c programmer, I'm not sure where to start. Any help would be appreciated.

Here is the debugging output:

2011-07-07 15:27:44.333 App[5836:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 6 beyond bounds [0 .. 5]'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x013d0be9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x015255c2 objc_exception_throw + 47
    2   CoreFoundation                      0x013c66e5 -[__NSArrayM objectAtIndex:] + 261
    3   CollegeFootballAlerts               0x00034892 -[SMStandings tableView:cellForRowAtIndexPath:] + 397
    ...
)
terminate called after throwing an instance of 'NSException'

the breakpoint is here at teamsInfo = :

- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString* cellIdentifier = @"TeamsInfoCell"; 

    SMStandingsTableViewCell * cell = (SMStandingsTableViewCell *)[tableView1 dequeueReusableCellWithIdentifier:cellIdentifier];
    if( cell == nil ){
        [[NSBundle mainBundle] loadNibNamed:@"SMStandingsTableViewCell" owner:self options:nil];
        cell = standingsTableCell;
        standingsTableCell = nil;
    }
    SMTeamsInfo * teamInfo;
        NSMutableArray * teamsInGroup = [allGroups objectForKey:[allKeys objectAtIndex:indexPath.section]];
        NSLog(@"TEAMS IN GROUP %@ :: %d", teamsInGroup, indexPath.row);
        teamInfo = [teamsInGroup objectAtIndex:indexPath.row];

    [[cell teamName] setText:[teamInfo nameEN]];
    [[cell teamFlag] setImage:[teamInfo teamFlag]];
    NSString * str;
    if([segmentedControl selectedSegmentIndex] == 0) {               // for conference tab wonconf - lostconf  combination is used 
        str= [NSString stringWithFormat:@"%@",[teamInfo wonconf]];
        str = [str stringByAppendingString:@"-"];
        str = [str stringByAppendingFormat:@"%@",[teamInfo lostconf]];
    }else {                                                          // for overall tab wonconf - lostconf  combination is used 
        str= [NSString stringWithFormat:@"%@",[teamInfo wonall]];
        str = [str stringByAppendingString:@"-"];
        str = [str stringByAppendingFormat:@"%@",[teamInfo lostall]];
    }

    [[cell currentStanding ]setText:str];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;    
}

and the numberOfRowsInSection method:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray * array = [allGroups allKeys];
    NSLog(@"NO OF ROWS IN SECTION #%d : %d", section, [[allGroups objectForKey:[array objectAtIndex:section]] count]);  
    return [[allGroups objectForKey:[array objectAtIndex:section]] count];
}

and the output of that method:

2011-07-08 17:46:13.837 App[7513:207] NO OF ROWS IN SECTION #1 : 7
2011-07-08 17:46:13.837 App[7513:207] NO OF ROWS IN SECTION #0 : 6

not sure why section #1 coming in first... the number of rows is reverse. it should be 7 for section 0 and 6 for section 1 which seems like the root of the problem.

2 Answers 2

3

did you get this in xcode while debugging? if so it should auto take you to the line it happens on.

If not, it is happening from the looks of things somewhere in SMStanding's tableView: cellForRowAtIndexPath: method. and looks like a generic array out of bounds issue. If you need help with that, edit your question with the code from that method.

Edit: In general, for this kind of stack trace, I try to find a class name/method that is something that I made and go from there.

Sign up to request clarification or add additional context in comments.

6 Comments

i did indeed get it from xcode console. how can i get it to take me to the line it happened on?
it should automatically do it in the code window. its semi annoying actually. if not, try clicking on the error in the error/warning list (if in xcode 4 in the left pane 4th button the exclamation point in triangle)
added the breakpoint in an edit... haven't made it any further yet.
check your numberOfRowsForSection: method to make sure it is correct. Looks like your creating too many rows for a particular section's array. Hard to tell much more than that.
there is a table view with two sections, one with 7 rows and one with 6. the first section is showing the right data, and the array (teamsInGroup) shows the right amount of entries (7) in debugging output, but there are only 6 displayed before going to the second section. here all rows are displayed properly, but when scrolling to the end i think it looks for the missing row from section one.
|
1

that means you have an NSArray with 6 items and you asked for index 6 which doesn't exits, only indexes 0..5 inclusively exist.

this is happening inside of your table view delegate method [SMStandings tableView:cellForRowAtIndexPath:], it is possible you are returning a number too high in
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

2 Comments

yeah, got the gist of the error. but i can't seem to find where that array is defined to allocate for the additional index.
well it is pulled out of another object, probably a dictionary here: NSMutableArray * teamsInGroup = [allGroups objectForKey:[allKeys objectAtIndex:indexPath.section]]; NSLog(@"TEAMS IN GROUP %@ :: %d", teamsInGroup, indexPath.row); teamInfo = [teamsInGroup objectAtIndex:indexPath.row];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.