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
Contributor
Posts: 14
Registered: ‎07-02-2012
My Device: BlackBerry 9930
My Carrier: BlackBerry

Runtime Exception in Send Message in BlackBerry

[ Edited ]

I am getting RunTime Exception when I am Running this code..Please Go Through it and Help me if you have any idea. Thanks..

private void sendSMS(String phone, String message) throws IOException 
    {

//       TODO Auto-generated method stub
        Dialog.alert("Hello..In Send SMS Function");
        System.out.println("in send sms function");

        MessageConnection conn =
            (MessageConnection)Connector.open("sms://+919925369855");
        TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
        tmsg.setAddress("sms://+919429441335");
        tmsg.setPayloadText("HIIiii");
        System.out.println("Text message is>>"+tmsg);
        conn.send(tmsg);
}
Developer
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: Runtime Exception in Send Message in BlackBerry

Which exception you are getting?

 

Thanks.

Contributor
Posts: 14
Registered: ‎07-02-2012
My Device: BlackBerry 9930
My Carrier: BlackBerry

Re: Runtime Exception in Send Message in BlackBerry

[ Edited ]

I am getting RunTime Exception.

 

Exception is >>java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

Developer
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10
My Carrier: Aircel

Re: Runtime Exception in Send Message in BlackBerry

use the code in try catch block.

Developer
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10
My Carrier: Aircel

Re: Runtime Exception in Send Message in BlackBerry

use this code may be it will help.

 

try {
				conn = (MessageConnection) Connector.open("sms://"+ strNumber);
				
				  TextMessage msgOut = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
				  msgOut.setPayloadText(strMessage);
				 
				  conn.send(msgOut);
				 
		} catch(Exception e) {
			System.out.println("Exception in SMS sending"+e.toString());
		} finally {
			try {
				conn.close();
				conn = null;
			} catch(Exception e){}
		}

 

Highlighted
Developer
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: Runtime Exception in Send Message in BlackBerry

[ Edited ]

There are two things which may causes error,

 

1. Dont use your message sending code in Event Thread, try to write in separate thread.

2. Dont show Dialog alert because if it is EventThread, then you may get error, instead of that try to print in console.

 

Thanks.