Nico
Nico

Reputation: 215

NSArray problem with addressbook

I have implemented an addressbook, I don't know what I do wrong, but whenever I select an address my whole app crashes and i receive the error

> 2010-10-21 11:57:13.922 ANWB[2989:207]
> *** Terminating app due to uncaught exception 'NSRangeException', reason:
> '*** -[NSCFArray objectAtIndex:]:
> index (0) beyond bounds (0)'
> 2010-10-21 11:57:13.935 ANWB[2989:207]
> Stack: (
>     843263261,
>     825818644,
>     842812211,
>     842812115,
>     862975761,
>     863130919,
>     110753,
>     870859136,
>     870898732,
>     870982260,
>     870977388,
>     844473760,
>     844851728,
>     862896011,
>     843011267,
>     843009055,
>     860901832,
>     843738160,
>     843731504,
>     9921,
>     9836 )

My code looks like this:

ABPeoplePickerNavigationController *picker =
            [[ABPeoplePickerNavigationController alloc] init];
            picker.peoplePickerDelegate = self;

            [picker setDisplayedProperties:[NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonAddressProperty]]];

            [self presentModalViewController:picker animated:YES];
            [picker release];

- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker {
    [self dismissModalViewControllerAnimated:YES];
}

- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {
    return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier {
    // Only inspect the value if it's an address.
    if (property == kABPersonAddressProperty) {
        ABMutableMultiValueRef multiValue = ABRecordCopyValue(person, property);
        for(CFIndex i=0;i<ABMultiValueGetCount(multiValue);i++)
        {
            CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multiValue, i)

;

.....

I don't know why it's telling me that an array created this error

please help me

Edit: Guys, Thanks for the answers, but apparently the problem wasn't even in this code it was a problem from somewhere else really appreciate the help though

Upvotes: 0

Views: 245

Answers (2)

jlehr
jlehr

Reputation: 15597

The log message is telling you exactly what went wrong:

*** Terminating app due to uncaught exception 'NSRangeException', reason:
'*** -[NSCFArray objectAtIndex:]:
index (0) beyond bounds (0)'

This says the your code is attempting to access the first element (index 0) of an empty array (bounds 0). Before running your for loop, make sure you use ABMultiValueGetCount to see if the array is empty, and only enter the loop if the array's not empty.

Upvotes: 1

exception
exception

Reputation: 618

Is this on the hardware or the simulator?

If you run with debug on the simulator, then the stack trace will show you which of your code lines caused the eventual problem.

Although it might be in a library, it will have its origin with one of your code lines.

Upvotes: 0

Related Questions