BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   Cannot Fetch ATTR_MOBILE parameter from address book (http://www.blackberryforums.com/developer-forum/142151-cannot-fetch-attr_mobile-parameter-address-book.html)

baran_khan 07-26-2008 03:26 AM

Cannot Fetch ATTR_MOBILE parameter from address book
 
HI,

I am trying to fetch the mobile number of the contact from the address book.

When I try following command:
phone= contact.getString(Contact.TEL, Contact.ATTR_FAX);

it works fine and fetch me the fax number of the contact, but when I replace "ATTR_FAX" with "ATTR_MOBILE" am getting null in return. Although I have filled all the values in the address book for the contact.

Any idea bout where I might be wrong????

baran_khan 07-28-2008 05:40 AM

Quote:

Originally Posted by baran_khan (Post 1033843)
HI,

I am trying to fetch the mobile number of the contact from the address book.

When I try following command:
phone= contact.getString(Contact.TEL, Contact.ATTR_FAX);

it works fine and fetch me the fax number of the contact, but when I replace "ATTR_FAX" with "ATTR_MOBILE" am getting null in return. Although I have filled all the values in the address book for the contact.

Any idea bout where I might be wrong????

Ok...here is the code...can anyone plz explain where am I going wrong...i got this code working if I fetch a fax number for the same contact...but will return null if I look for the mobile number instead of the fax...

PHP Code:

                    list = PIM.getInstance().openPIMList(PIM.CONTACT_LISTPIM.READ_ONLY);

                    
Enumeration contactEnum = list.items();


                    while(
contactEnum.hasMoreElements()){
                        
                        
temps++;
                        
Contact contact = (Contact)contactEnum.nextElement();
                        
intxxx91;xxx93; fieldIds contact.getFields();
                        
int id;
                        
name contact.getStringArray(contact.NAME0);
                        
phonecontact.getString(Contact.TELContact.ATTR_MOBILE);
                        
                    } 

Thanks in advance!!!

PaoloLim 07-28-2008 03:03 PM

The attribute constant isn't the same as the index number. I'm assuming you're getting an arrayindexoutofbounds exception or nullreference exception. Best way I can think of is to do something like:

Code:

for(int y=0; y < contact.countValues(Contact.TEL); y++)
{
    if(contact.getAttributes(Contact.TEL, y) == Contact.ATTR_MOBILE)
        phone = contact.getString(Contact.TEL, y); 
}

The reason the fax attribute constant is working is that it happens to be low enough to be an actual index.

EDIT: Sorry, that's a lowercase c on contact.getAttributes.

baran_khan 07-30-2008 05:54 AM

Quote:

Originally Posted by PaoloLim (Post 1036520)
The attribute constant isn't the same as the index number. I'm assuming you're getting an arrayindexoutofbounds exception or nullreference exception. Best way I can think of is to do something like:

Code:

for(int y=0; y < contact.countValues(Contact.TEL); y++)
{
    if(contact.getAttributes(Contact.TEL, y) == Contact.ATTR_MOBILE)
        phone = contact.getString(Contact.TEL, y); 
}

The reason the fax attribute constant is working is that it happens to be low enough to be an actual index.

EDIT: Sorry, that's a lowercase c on contact.getAttributes.

HI,

Sorry for not replying you this long...was on holiday...u know what it actually works...but I am not really satisfied with the way they are dealing with this....instead of doing it this way..they should have maintained the index names associated with the values that are being stored...instead of having it changed every time we make a change in the contacts...but I guess this is for saving the memory...

Thanks for ur support..i ll look forward for such responses and hope we can share a bag full of knowledge in future.....


All times are GMT -5. The time now is 01:49 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.