Welcome!

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

Reply
Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified
Accepted Solution

Strange thing happen in adding phone number

Hi all,

 

I'm tring to add a phone number to phone book.

However, my application brings original device phonebook application. Is this the normal behavior?

I want to add silently, and other thing is that when I click trackweel on objectChoiceField, it also bring device's [honebook application.

 

I used the action in trackwheelClick().

public boolean trackwheelClick(int status, int time) { Contact contact=null; int type=0; Field leafField = this.getLeafFieldWithFocus(); try { BlackBerryContactList contactList = (BlackBerryContactList)BlackBerryPIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE); PIMItem pimItem = contactList.choose(); contact = (BlackBerryContact)pimItem; } catch (PIMException e) { } if (leafField == okBttn) { contact.addString(Contact.NAME_FAMILY, BlackBerryContact.NAME_FAMILY, givenName.getText()); contact.addString(Contact.NAME_GIVEN, BlackBerryContact.NAME_GIVEN, familyName.getText()); if (pChoice.getSelectedIndex()==0) type = BlackBerryContact.ATTR_MOBILE; else if(pChoice.getSelectedIndex()==1) type = BlackBerryContact.ATTR_WORK; else if(pChoice.getSelectedIndex()==2) type = BlackBerryContact.ATTR_HOME; contact.addString(Contact.TEL,type, areaCode.getText() + phoneNum.getText()); try { contact.commit(); } catch (PIMException e) { } } return false; }

Please help me to fix this.

 

Thanks,

DK

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Strange thing happen in adding phone number

[ Edited ]

 

Before adding/processing fields/attributes check them before - are they supported or not.

 

javax.microedition.pim.PIMList has the following methods with names start with isSupportedxxxxx

 

 

isSupportedField, isSupportedAttribute, etc ...


 

Message Edited by tbilisoft on 09-01-2009 01:01 PM
Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: Strange thing happen in adding phone number

Hi,

 

I have changed the part as you recommended, now I'm getting IllegalArgumentException on addStringArray().

try { BlackBerryContactList contactList = (BlackBerryContactList)PIM.getInstance().openPIMList(BlackBerryPIM.CONTACT_LIST, PIM.READ_WRITE); //PIMItem pimItem = contactList.createContact(); Contact contact = contactList.createContact(); //contact = (BlackBerryContact)pimItem; String[] name= new String[7]; name[Contact.NAME_FAMILY] = familyName.getText(); name[Contact.NAME_GIVEN] = givenName.getText(); if(contactList.isSupportedField(Contact.NAME)) { contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, name); } if(contactList.isSupportedField(Contact.TEL)){ if (pChoice.getSelectedIndex()==0) type = Contact.ATTR_MOBILE; else if(pChoice.getSelectedIndex()==1) type = Contact.ATTR_WORK; else if(pChoice.getSelectedIndex()==2) type = Contact.ATTR_HOME; contact.addString(Contact.TEL,type, areaCode.getText() + phoneNum.getText()); } contact.commit();

What is wrong?

 

Thanks,

DK

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Strange thing happen in adding phone number

Please refer to the sample here:

 

How To - Access Address Book contacts
Article Number: DB-00147

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800363/How_To_...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: Strange thing happen in adding phone number

I solved the problem.

 

The problem was

String[] name= new String[7]; <<<<--------- I changed to   String[] name= new String[5]; 
          name[Contact.NAME_FAMILY] = familyName.getText();
        name[Contact.NAME_GIVEN] = givenName.getText();
         
Thanks,

DK

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Strange thing happen in adding phone number

Note that the NAME field is a STRING_ARRAY field that can vary in size.  A hard coded array size should not be used.  Instead, you can create the array with the size returned from ContactList.stringArraySize(Contact.NAME) to avoid future issues.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: Strange thing happen in adding phone number

Mark,

 

This is good information.

I'll take this.

 

Thanks,

DK