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
New Developer
Posts: 3
Registered: ‎11-14-2008
My Device: Not Specified

Code to remove phone number from contact not working in OS ver 4.5

Following Code Works properly in OS ver 4.2 but throws indexOutOfBound Exception in OS ver 4.5

I am able to remove phone number from blackberry contact using below code in Blackberry 4.2 but not able to do same in 4.5. After debugging i got results that before "statement 1" contact.countValues(BlackBerryContact.TEL) returns integer 3 if there are 3 phone numbers(for example 3) but after execauting  "statement 1" contact.countValues(BlackBerryContact.TEL) returns integer value 6 and this causes the generation of exception.

**Note** Adderess contains fields as follows

First    vinay

Work   999999999

Home  333333333

Mobile 444444444

 

Now when i try to update this address by following code i get exception in "statement 2"

How do i remove phone numbers from contact in OS ver 4.5

 

 

String[] name = null;

boolean nameFlag = false;
           
            if(contact.countValues(BlackBerryContact.NAME)>0)
            {
              contact.removeValue(BlackBerryContact.NAME,0);//statement 1

           }
            ContactList contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
            name = new String[contactList.stringArraySize( BlackBerryContact.NAME)];
            if(jsonContact.has("TITLE"))
            {
                if(jsonContact.get("TITLE")!=null && !jsonContact.get("TITLE").equals(""))
                {
                    name[BlackBerryContact.NAME_PREFIX]=jsonContact.get("TITLE").toString().trim();
                    nameFlag = true;
                }
            }if(jsonContact.has("FNAME"))
            {
                if(jsonContact.get("FNAME")!=null && !jsonContact.get("FNAME").equals(""))
                {
                    name[BlackBerryContact.NAME_GIVEN]=jsonContact.get("FNAME").toString().trim();
                    nameFlag = true;
                }
            }if(jsonContact.has("LNAME"))
            {
                if(jsonContact.get("LNAME")!=null && !jsonContact.get("LNAME").equals(""))
                {
                    name[BlackBerryContact.NAME_FAMILY]=jsonContact.get("LNAME").toString().trim();
                    nameFlag = true;
                }
            }
            if(nameFlag)
            {
                contact.addStringArray(BlackBerryContact.NAME,Contact.ATTR_NONE,name);//Name
            }

 

 

 

    int countPhones= contact.countValues(BlackBerryContact.TEL);
            for (int atrCount = 0;atrCount <countPhones ;atrCount++)
            {               

              switch(contact.getAttributes(BlackBerryContact.TEL,0))


                {

              case BlackBerryContact.ATTR_WORK:
            contact.removeValue(BlackBerryContact.TEL,0);// statement 2
                    break;
                 
                 case BlackBerryContact.ATTR_HOME:
                    contact.removeValue(BlackBerryContact.TEL,0);
                    break;
                   
                 case BlackBerryContact.ATTR_MOBILE:
                    contact.removeValue(BlackBerryContact.TEL,0);    
                    break;
                  
                 case BlackBerryContact.ATTR_PAGER:
                    contact.removeValue(BlackBerryContact.TEL,0);   
                    break;
                 
                 case BlackBerryContact.ATTR_FAX:
                    contact.removeValue(BlackBerryContact.TEL,0);
                    break;
                
                 case BlackBerryContact.ATTR_OTHER:
                    contact.removeValue(BlackBerryContact.TEL,0);
                    break;                
              }
            }
BlackBerry Development Advisor
Posts: 15,784
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Code to remove phone number from contact not working in OS ver 4.5

I have been able to reproduce this issue in BlackBerry handheld software version 4.5 and 4.6.  However, the problem has been resolved in BlackBerry handheld software version 4.7.0.

 

As a work around, you can trap the exception and continue with your logic for the affected releases.

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
New Developer
Posts: 1
Registered: ‎12-12-2008
My Device: Not Specified

Re: Code to remove phone number from contact not working in OS ver 4.5

does this mean that if that number, 999999999,  shows up that a phone number in the contact list has been changed so it can't be viewed?
Highlighted
BlackBerry Development Advisor
Posts: 15,784
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Code to remove phone number from contact not working in OS ver 4.5

I'm not sure what you are asking...
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