problem adding contacts

Hi all

I am trying to add a contact to the contacts list blackberry dynamically, this is the

code snippet and I get an illegal argument exception, y at - it something that miss me in

the code below, please help me get rid of this problem...

public void savingcontact()
    {
        String companyString = detailFields[0].toString();
        String firstString = detailFields[1].toString();
        String lastString = detailFields[2].toString();
        String emailString = detailFields[3].toString();
        String phoneString = detailFields[4].toString();
        Dialog.alert(firstString+"\n"+lastString+"\n"+emailString+"\n"+companyString+"\n"+phoneString);

        BlackBerryContactList contactList;
        BlackBerryContact new_contact;
        try
        {
            contactList = (BlackBerryContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
            new_contact = (BlackBerryContact) contactList.createContact();
            if (contactList.isSupportedField(Contact.ORG))
            //new_contact.addString(Contact.ORG, PIMItem.ATTR_NONE,"Acme, Inc.");
                new_contact.addString(Contact.ORG, PIMItem.ATTR_NONE,companyString);
            if(contactList.isSupportedField(Contact.NAME))
                new_contact.addString(Contact.NAME, PIMItem.ATTR_NONE, firstString);
            if(contactList.isSupportedField(Contact.NAME_FAMILY))
                new_contact.addString(Contact.NAME_FAMILY, PIMItem.ATTR_NONE, lastString);
            if (contactList.isSupportedField(Contact.TEL))
                new_contact.addString(Contact.TEL, PIMItem.ATTR_NONE, phoneString);
            if (contactList.isSupportedField(Contact.EMAIL))
                new_contact.addString(Contact.EMAIL,PIMItem.ATTR_NONE, emailString);
            try
            {
                // commits it to the list and the native database
                new_contact.commit();
            }
            catch (Exception e)
            {
                // failed committing the contact
                System.err.println("This application cannot add the contact info");
            }
            contactList.close();
        }
        catch (Exception e)
        {
        // failed to close the list
            Dialog.alert(e.toString());
        }
}

Thanks in advance

You set the field name to evil.

Here's an example shot the javadocs.

if (contacts.isSupportedField(Contact.FORMATTED_NAME)
       contact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE, "Mr. John Q. Public, Esq.");
  if (contacts.isSupportedArrayElement(Contact.NAME, Contact.NAME_FAMILY))
       name[Contact.NAME_FAMILY] = "Public";
  if (contacts.isSupportedArrayElement(Contact.NAME, Contact.NAME_GIVEN))
       name[Contact.NAME_GIVEN] = "John";
  contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, name);

Tags: BlackBerry Developers

Similar Questions

Maybe you are looking for

  • Audio system on MacPro early does not.

    A symbol of the "oblique/circle bar" appears on the screen when I press the volume to the top or to the bottom of the key.  I just reinstalled Yosemite after an accident on my MacPro (2008). Everything else works fine.

  • Why AutoSave does not work?

    My speech has stopped its work of automatic backup. If I saved the file once or not, I'll have more in more frequent crashes and all the work disappeared. I reinstalled the software and updated, but the problem is recurring. Ideas? (A hint: I always

  • Disable thumbnails of images

    Is there a way to disable the thumbnails that appear in the Skype chat? I need to be able to see when an image is sent then is it possible to return it when he appeared as a file transfer. I can't seem to find an option to disable the thumbnails, I t

  • on the guarantee to operatin system

    Mr President If at all... I update to windows 8.1 have guaranteed with my windows 8. windows 8.1 hangs on... am I going to get the support of HP to warranty...

  • DESKJET 3636: Once again, problems with drivers, ob! DESKJET 3636

    Here we are I am still here to complain for the installation of the drivers, this time with Win10 and a new printer, but the same question that in past. It seems that HP engineer have used bad and strange to pursue a way to write the drivers which co