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

New Developer
Posts: 83
Registered: ‎02-22-2009
My Device: Not Specified
Accepted Solution

how to exit AddressBook ?

when i choose a contact,  i can back to the editField interface  and get the TEL set it on the editField,

but now if i don't chosse any contact , i want back to editField interface , it shows Nullpointer Exception,

so how can i exit AddressBook ?

my showAddressBook code : 

public void showAddressBook() {
      try {
          BlackBerryContactList contactList = (BlackBerryContactList)BlackBerryPIM.getInstance().openPIMList(BlackBerryPIM.CONTACT_LIST, BlackBerryPIM.READ_WRITE);
          BlackBerryContact contact = (BlackBerryContact)contactList.choose(null, BlackBerryContactList.AddressTypes.EMAIL,true);
          String mobileNumber = "";
          int numValues = 0;
          numValues = contact.countValues(BlackBerryContact.TEL);
          for (int i = 0; i < numValues; i++) {
              if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) {
                  mobileNumber = contact.getString(BlackBerryContact.TEL, i);
      } catch (PIMException ex) {

Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: how to exit AddressBook ?

Use debugger to find which object is null which you are trying to access.

Use Search. "Accept Solution" If the problem is resolved.
Posts: 17,023
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to exit AddressBook ?

if the user decides not to choose a contact you get null as a return value. your code has to check this.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
BlackBerry Development Advisor
Posts: 15,859
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: how to exit AddressBook ?

As Simon pointed out, you'll need to verify that the choose method didn't return null.


I also recommend you use the choose() method instead of the deprecated choose(Contact previous, int type, boolean allowCrossService) method. 



Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
New Developer
Posts: 9
Registered: ‎01-21-2009
My Device: Not Specified

Re: how to exit AddressBook ?

Hi guys,



When i use the choose() method, the contatcs list isnt launched, and i dont get an error, any idea why this happens?


how do i actaully set the contatct list to be displayed? display.setCurrentDisplay(List); ?? doesnt seem to work.


this is what i gt back fromt he debuger when i call the showAddressBook Method written by ashengjie


Starting net_rim_bb_simphonebook
Started net_rim_bb_simphonebook(126)
EF: 20 SIZE: -1
JVM: bklt @8179: timer
JVM: bklt @8179: idle 2
JVM: bklt @8179: setTimer 20
Exit net_rim_bb_simphonebook(126)