1

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://+919099956325");
        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);
}
Riddhi Barbhaya
  • 1,205
  • 1
  • 11
  • 19
  • 1
    check out the link http://stackoverflow.com/questions/12801267/how-to-send-sms-programatically-in-blackberry – AK Joshi Oct 12 '12 at 10:29
  • @Anzy_..Its also My Question but Answers getting in That Question are not working properly,..As Per my requirement..Thanks for Reply and Suggestion.. – Riddhi Barbhaya Oct 12 '12 at 12:38

1 Answers1

1

instead of System.out.println("Text message is>>"+tmsg);

use

System.out.println("Text message is>>"+tmsg.getPayloadText());

Also Connector.open is a blocking operation and should not be called from a main event thread.

You have Dialog.alert which will only work on a event thread. Do this

UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                Dialog.alert("Hello..In Send SMS Function");
                }
            });

Try this code . this starts a new thread and calls sendsms method

new Thread(new Runnable() {

        public void run() {
             try {
                sendSMS("123456789","message");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }).start();

          private void sendSMS(String phone, String message) throws IOException 
          {
    try {
        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
            Dialog.alert("Hello..In Send SMS Function");
            }
        });
        System.out.println("in send sms function");

        MessageConnection conn =
            (MessageConnection)Connector.open("sms://+919099956325");
        TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
        tmsg.setAddress("sms://+919429441335");
        tmsg.setPayloadText("HIIiii");
        System.out.println("Text message is>>"+tmsg.getPayloadText());
        conn.send(tmsg);
    } catch (Exception e) {
        System.out.println("Exception is >>"+e.toString());
    }
}
rfsk2010
  • 8,571
  • 4
  • 32
  • 46
  • Thanks a lot..For your Reply..I corrected my mistake as System.out.println("Text message is>>"+tmsg.getPayloadText()); And I had added UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { Dialog.alert("Hello..In Send SMS Function"); } }); I am still getting RunTime Exception. Please your suggestion helped me a lot..Please Now suggest something..please..Thanks in Advance.. – Riddhi Barbhaya Oct 12 '12 at 11:03
  • Thanks once Again for Your Reply..Now i am getting... Exception is >>java.lang.RuntimeException: blocking operation not permitted on event dispatch thread This Exception I am getting.. – Riddhi Barbhaya Oct 12 '12 at 12:27
  • 1
    you should not call that method from event thread. check the answer now – rfsk2010 Oct 12 '12 at 13:26