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
Developer
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

BlackberryMessenger.chooseContact() spits exception when there is no BBM contact found

Hi,

 

 

I am trying to use the BlackberryMessenger API in the simulator. When I call BlackberryMessenger.chooseContact() that method attempts to present the user with a UI to choose a BBM contact. This process involves sorting. 

 

I have encountered an exception during the sorting, because in the simulation there is no BBM contact available, and thus I got an ArrayIndexOutOfBoundsException during a SimpleSortingVector.elementAt(int) call. I got that information from the debugger's stack trace.

 

Seems to me that the way around this is to first check if there is > 0 BBM Contacts available, but I haven't found a method to do this. 

 

Can anyone please tell me how to find out the # of BBM Contacts available, or a better method to handle this situation?

 

Thanks!

Developer
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: BlackberryMessenger.chooseContact() spits exception when there is no BBM contact found

anyone?
Developer
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: BlackberryMessenger.chooseContact() spits exception when there is no BBM contact found

anyone got a clue?

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: BlackberryMessenger.chooseContact() spits exception when there is no BBM contact found

Have you tried catching the exception when calling chooseContact()?

 

 

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: BlackberryMessenger.chooseContact() spits exception when there is no BBM contact found

[ Edited ]

Make sure that BlackberryMessenger.getInstance() does not return null. If it doesn't you are safe to call BlackberryMessenger.getInstance().chooseContact().

 

 

BlackberryMessenger bbm = BlackBerryMessenger.getInstance();

if (bbm != null) {
MessengerContact bbmContact = bbm.chooseContact();
}

 


Warning: As of this writing, the BlackberryMessenger API implementation was accidentally left out of the most recent versions of BBM (5.0.0.33 all the way up to 5.0.0.57) out so whatever you're trying to do won't work on a live device with a new version of BBM.

 

Below is a link to the bug in the issue tracker:

 

BlackBerryMessenger.getInstance() returns null with latest BlackBerry Messenger 5.0.0.33 installed

 

Please watch/vote on it as it is an necessary fix what you're trying to create.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Developer
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: BlackberryMessenger.chooseContact() spits exception when there is no BBM contact found

[ Edited ]

Thanks for your reply. I am actually using the code from the Tic Tac Toe demo and the code is identical to what you pasted above, yet I am still getting the exception I mentioned. I think what getInstance() does is makes sure BBM is installed, no? chooseContact() tries to sort all the contacts in the contact list, and when there is no one in the contact list, that's when the exception happens. At least that's what I theorized just from looking at the stack trace. 

 

by the way what I am trying to do is all on simulation, so I don't know if that bug you mentioned affects this. also, I am using JDE 4.5. what do you think?

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: BlackberryMessenger.chooseContact() spits exception when there is no BBM contact found

[ Edited ]

The problem is that you cannot test the BlackberryMessenger API on the simulator since BBM isn't installed. The code does test to see if BBM is installed and when BlackberryMessenger.getInstance() returns null, it (is supposed to mean) isn't installed.

 

Looking at the API reference, the BlackberryMessenger.chooseContact() method is abstract so you have to call it from an instance of the BlackberryMessenger object. That is the reason you need to use getInstance() first.

 

Secondly, you have to make sure you are getting the event lock before calling chooseContact().

 

You can try:

 

 

final BlackberryMessenger bbm = BlackBerryMessenger.getInstance();

if (bbm != null) {
MessengerContact bbmContact = null;

UiApplication.getUiApplication().invokeAndWait(new Runnable(){
public void run() {
bbmContact = bbm.chooseContact();
}
});
}

 

 

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Developer
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: BlackberryMessenger.chooseContact() spits exception when there is no BBM contact found

 


jcarty wrote:

The problem is that you cannot test the BlackberryMessenger API on the simulator since BBM isn't installed. 

 


 

 

aahhh that's it. is that true for all the simulators?

 

how did you even know that piece of information? 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: BlackberryMessenger.chooseContact() spits exception when there is no BBM contact found

[ Edited ]

Created a few games that use BBM. Waiting on them to fix the issue in the latest versions so I can release them in App World. Worked great when it was available.

 

And it is true for all simulators. I do wish for a simulator for interaction with BBM too.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
New Developer
Posts: 4
Registered: ‎01-12-2010
My Device: Bold - 9000
My Carrier: AT&T

Re: BlackberryMessenger.chooseContact() spits exception when there is no BBM contact found

guyz,

 

I've been facing very different problem regarding Blackberry Messenger.

 

I'm using TicTacToe demo app for BB 4.5.0.

 

It works pretty fine on the simulator.

 

But on actual device(version 4.5.0) , it gives "No BlackBerry Messenger Installed" , when i click on "Second Player" option.

 

I can get BBM instance on the simulator , but on the device it's NULL.Smiley Sad

 

I have downloaded & installed the required BBM.

& my app is signed also.

I can't figure it out..

plzz help me out...