Reputation: 1205
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);
}
Upvotes: 1
Views: 305
Reputation: 8611
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());
}
}
Upvotes: 1