Troubleshooting guide
173
11: Using PIM applications
Change contact information. 1. To change the name and address fields, invoke the appropriate set method to replace
an existing value with a new value.
2. Perform one of the following actions:
• To change the fields that support a single value, retrieve the array and then change
one or more indexes in the array before adding the array back to the
Contact
object.
if (contact.countValues(Contact.NAME) > 0) {
String[] newname = contact.getStringArray(Contact.NAME, 0);
}
// Change the prefix to Dr. and add the suffix, Jr.
newname[Contact.NAME_PREFIX] = "Dr.";
newname[Contact.NAME_SUFFIX] = "Jr.";
contact.setStringArray(Contact.NAME, 0, Contact.ATTR_NONE,
newname);
• To change the contacts fields that support multiple values, before adding another
value, verify that the number of values does not exceed the maximum number of
values. For example:
if (contact.countValues(Contact.EMAIL) <
contactList.maxValues(Contact.EMAIL)) {
contact.addString(Contact.EMAIL, Contact.ATTR_NONE,
"aisha.wahl@blackberry.com");}
3. Create code to manage a FieldFullException, which occurs if you invoke an add
method, such as
addString(), for a field that already has a value.
Save a contact. 1. To determine if any contact fields have changed since the contact was last saved,
invoke
isModified().
2. Invoke commit().
if(contact.isModified()) {
contact.commit();
}
Task Steps