Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 30
Registered: ‎06-01-2009
My Device: 9000 Bold
Accepted Solution

Problem adding contact to phone

[ Edited ]

Hi all,



I'm trying to add a contact to the contact list of the phone, by wirting this code :



      ContactList contacts = null;
      try {
         contacts = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
      } catch (PIMException e) {
         // An error occurred
      Contact contact = contacts.createContact();

     String[] name = new String[ contacts.stringArraySize( Contact.NAME ) ];
     name[Contact.NAME_GIVEN] = "Kate";
     name[Contact.NAME_FAMILY] = "Turner";
     contact.addStringArray(Contact.NAME, Contact.ATTR_NONE, name);
     AddressBookArguments entry = new AddressBookArguments(AddressBookArguments.ARG_COMPOSE, contact);

     Invoke.invokeApplication(Invoke.APP_TYPE_ADDRESSBOOK, entry);

catch (Exception e)
    System.out.println("erreur ms avt ps disp addContactToRep " + e.getMessage());

 but I get an exception during debugging, on the line "AddressBookArguments entry = new AddressBookArguments(AddressBookArguments.ARG_COMPOSE, contact);"


The error message is : Invalid argument


I'm trying to use the code brought by the api, but it seems what I wrote is wrong...




Could you please help me?



Message Edited by sheepk on 09-25-2009 07:36 PM
Message Edited by sheepk on 09-25-2009 07:54 PM
Posts: 166
Registered: ‎01-14-2009
My Device: Curve 8330

Re: Problem adding contact to phone


you can try to cast the PIm.getInstance() to BlackBerryContactList instead of ContactList.

Maybe you'll need to change the  AddressBookArguments.ARG_COMPOSE to AddressBookArguments.ARG_NEW.


Hope that will help. 

Thank you, have a nice day.

Samuel D.
Posts: 30
Registered: ‎06-01-2009
My Device: 9000 Bold

Re: Problem adding contact to phone



It works by putting ARG_NEW. Without you I wouldn't have tried this option, because I wanted to get a pre-completed form...


I don't undestand why it doesn't work with ARG_COMPOSE option... do you have an explanation?