IndexOutOfBoundsException when updating a contact in contact list - Blackberry

Posted by Taha on Stack Overflow See other posts from Stack Overflow or by Taha
Published on 2010-05-12T10:55:16Z Indexed on 2010/05/12 11:34 UTC
Read the original article Hit count: 797

Filed under:

Software and Simulator version i am using

Blackberry Smartphone simulator: 2.13.0.65

Blackberry software version 5.0.0_5.0.0.14

I am looking at modifying contacts. Below is the code snippet i am using. I am getting a IndexOutOfBounds Exception at line

  String wtel = blackBerryContact.getString(BlackBerryContact.TEL, supportedAttributes[i]);

Can someone advise what is going wrong here. Following is the code snippet

.....

// Load the addressbook and let the user choose from list of contact
BlackBerryContactList contactList = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE);
PIMItem pimItem = contactList.choose();
BlackBerryContact blackBerryContact = (BlackBerryContact)pimItem;
PIMList pimList = blackBerryContact.getPIMList();

// get the supported attributes for Contact.TEL
int[] supportedAttributes = pimList.getSupportedAttributes(Contact.TEL);

Dialog.alert("Supported Attributes "+supportedAttributes.length); // gives me 8

for (int i=0; i < supportedAttributes.length;i++){
    if(blackBerryContact.ATTR_WORK == supportedAttributes[i]){
        Dialog.alert("updating Work"); // This alert is shown
        Dialog.alert("is supported "+ pimList.isSupportedAttribute(BlackBerryContact.TEL, supportedAttributes[i])+" "+pimList.getAttributeLabel(supportedAttributes[i])); // shows true and work
        String wtel = blackBerryContact.getString(BlackBerryContact.TEL, supportedAttributes[i]); // I get a IndexOutOfBounds Exception here
        if(wtel != ""){
            pimItem.removeValue(BlackBerryContact.TEL, supportedAttributes[i]);
        }
        pimItem.addString( Contact.TEL, BlackBerryContact.ATTR_WORK, number); // passing the number that has to be updated 
        if(pimItem.isModified()) {
            pimItem.commit();
            Dialog.alert("Updated Work Number");
        }
    }
}

.....

I want to update all the supported attributes for Contact.TEL field

http://www.blackberry.com/developers/docs/5.0.0api/net/rim/blackberry/api/pdap/BlackBerryContact.html

Field       Values Per Field        Supported Attributes
-----------------------------------------------------------------------------
Contact.TEL         8         Contact.ATTR_WORK, Contact.ATTR_HOME, 
                      Contact.ATTR_MOBILE, Contact.ATTR_PAGER, 
                      Contact.ATTR_FAX, Contact.ATTR_OTHER, 
                      Contact.ATTR_HOME2, Contact.ATTR_WORK2

© Stack Overflow or respective owner

Related posts about blackberry