BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-23-2008, 11:38 AM   #1
smartmind
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: pearl
PIN: N/A
Carrier: none
Posts: 20
Default PhoneNumber retrieval from Address Book

Please Login to Remove!

I have the following code which would give me an indexoutofbounds error all the time. Is there anyone who could help me out with this.

The phonepacket is just a collector class that takes in the information given out by this method below. this.basecontact is the current contact which also works fine ( i checked and contact gets the values ok).

however the problem seems to be in this line "String phonenumber = this.baseContact.getString( Contact.TEL, attr);".

Code:

	public PhonePacket[] getPhoneNumbers(){
		if (!this.baseContact.getPIMList().isSupportedField(Contact.TEL))
			return null;
		int count = this.baseContact.countValues( Contact.TEL );
		if(count < 1)
			return null;
		PhonePacket[] v = new PhonePacket[ count ];
		int i;
		
		for(i=1;i<count;i++){
			int attr = this.baseContact.getAttributes(Contact.TEL,  i );

			String phonenumber = this.baseContact.getString( Contact.TEL, attr);
			v[i] = new PhonePacket(phonenumber, attr, i);			
		}

		return v;
	}
Offline  
Old 06-23-2008, 04:18 PM   #2
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

"attr" is a bitmask of attributes associated with that particular phone entry. In order to get the phone number itself you should do:

String phonenumber = this.baseContact.getString( Contact.TEL, i );

The PIM API is pretty darn confusing, IMO.
__________________
Do your homework and know how to ask a good question.
Offline  
Old 06-24-2008, 02:22 AM   #3
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

how did you get the numer from the addressbook in the first place?
the last time i tried the only working method was to get an email from it.

here is some code about grabbing the numbers from a contact, DialogNumberChooseItem is just a bean with number and description in it

Code:
results = new Vector();
BlackBerryContact contact = (BlackBerryContact) context;
int numValues = contact.countValues(BlackBerryContact.TEL);
for (int i = 0; i < numValues; i++) {
     if (contact.getAttributes(BlackBerryContact.TEL, i) == Contact.ATTR_WORK) {
        results.addElement(new DialogNumberChooseItem(resources.getString(WORK), contact.getString(BlackBerryContact.TEL, i)));
        } else if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_HOME) {
        results.addElement(new DialogNumberChooseItem(resources.getString(HOME), contact.getString(BlackBerryContact.TEL, i)));
        } else if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) {
        results.addElement(new DialogNumberChooseItem(resources.getString(MOBILE), contact.getString(BlackBerryContact.TEL, i)));
        } else if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_OTHER) {
        results.addElement(new DialogNumberChooseItem(resources.getString(OTHER), contact.getString(BlackBerryContact.TEL, i)));
        }
}
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 06-24-2008, 04:09 AM   #4
smartmind
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: pearl
PIN: N/A
Carrier: none
Posts: 20
Default

Quote:
Originally Posted by richard.puckett View Post
"attr" is a bitmask of attributes associated with that particular phone entry. In order to get the phone number itself you should do:

String phonenumber = this.baseContact.getString( Contact.TEL, i );

The PIM API is pretty darn confusing, IMO.
with i, it gives me an index out of bounds exception on i=0 while count values clearly gives me more than 1 available entries.
Offline  
Old 06-24-2008, 10:32 AM   #5
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Oh, just saw this in your code:

for(i=1;i<count;i++){

I just figured it was a standard for-loop. As is often the case, this might best be explained with code. PhoneNumber is a simple bean with public "number" and "attr" strings.

Code:
       
Vector phoneNumbers = new Vector();

int id = Contact.TEL;
int numValues = contact.countValues(id);

for (int i = 0; i < numValues; i++) {
   PhoneNumber newPhoneNumber = new PhoneNumber();

   newPhoneNumber.number = contact.getString(id, i);
            
   int attrs = contact.getAttributes(id, i);
   int[] supportedAttrs = contact.getPIMList().getSupportedAttributes(id);
            
   for (int j = 0; j < supportedAttrs.length; j++) {
      if ((attrs & supportedAttrs[j]) == supportedAttrs[j]) {
         String attrName = contact.getPIMList().getAttributeLabel(supportedAttrs[j]);
         newPhoneNumber.attr = attrName;
      }
   }
            
   phoneNumbers.addElement(newPhoneNumber);
}
__________________
Do your homework and know how to ask a good question.
Offline  
Old 06-24-2008, 07:09 PM   #6
smartmind
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: pearl
PIN: N/A
Carrier: none
Posts: 20
Default

Thanks a lot. The problem was corrected when i made a transition to Blackberrycontact instead of standard contact given in the PIM API by J2ME. there was some issue with the index accessing using the attributes that were retrieved using the methods and then with the usage of those as index. Aparently using native blackberrycontacts made it simple and effective.

I was able to retrieve all the phone numbers stored within the contact using a vector which was further used to create a live address book two level search. works fine and gives me live results like the standard address book search so thanks a lot for your help.

Have a nice day !
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


New Amiga Gotek OLED IIC I2C 0.91

New Amiga Gotek OLED IIC I2C 0.91" 128x32 LCD Display Module 3.3V 5V White 679

$7.17



RADSTONE VME BOARD PME 68-33 MOTOROLA 6800 33Mhz AMIGA PPC picture

RADSTONE VME BOARD PME 68-33 MOTOROLA 6800 33Mhz AMIGA PPC

$185.00



New Greaseweazle V4.1 USB Floppy Adapter Flux Reader Writer Amiga Atari ST 1591 picture

New Greaseweazle V4.1 USB Floppy Adapter Flux Reader Writer Amiga Atari ST 1591

$28.44



Vintage MOS 6502 6502A 6502AD 6502B DIP40 x 1pc picture

Vintage MOS 6502 6502A 6502AD 6502B DIP40 x 1pc

$5.99



1PC USED A54MA55B BC186A413G52 Mitsubishi A500/F540 Series 55KW Drive Board #CZ picture

1PC USED A54MA55B BC186A413G52 Mitsubishi A500/F540 Series 55KW Drive Board #CZ

$317.00



Mitsubishi FR-A540-0.75K-NA AC DRIVE INVERTER 1 HP 380-480 VAC 50/60 HZ 4.1 AMP  picture

Mitsubishi FR-A540-0.75K-NA AC DRIVE INVERTER 1 HP 380-480 VAC 50/60 HZ 4.1 AMP

$649.99







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.