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


Bissell 3-in-1 Lightweight Corded Stick Vacuum 2030 picture

Bissell 3-in-1 Lightweight Corded Stick Vacuum 2030

$28.88



Vacuum Air Fuel Water Line Tube Hose Barbed Connector Coupling Tee Elbow T X Y picture

Vacuum Air Fuel Water Line Tube Hose Barbed Connector Coupling Tee Elbow T X Y

$1.99



BISSELL 3-in-1 Turbo Lightweight Stick Vacuum, 2610 (Black) picture

BISSELL 3-in-1 Turbo Lightweight Stick Vacuum, 2610 (Black)

$37.96



Shark RV761_N Robotic Vacuum Cleaner With Charging Dock Navy Blue Black Tested picture

Shark RV761_N Robotic Vacuum Cleaner With Charging Dock Navy Blue Black Tested

$38.00



3 CFM Air Vacuum Pump HVAC Manifold Gauge Set AC A/C Refrigeration Kit picture

3 CFM Air Vacuum Pump HVAC Manifold Gauge Set AC A/C Refrigeration Kit

$47.55



VEVOR 5 Gallon Vacuum Chamber with 5CFM Vacuum Pump Kit 1/3HP Single Stage 110V picture

VEVOR 5 Gallon Vacuum Chamber with 5CFM Vacuum Pump Kit 1/3HP Single Stage 110V

$104.99







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