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
sandeepsagark
Posts: 41
Registered: ‎07-19-2011
My Device: 9500

illegal exception while sending a SMS

Hi,

 

I am working on SMS. I had tried with the following code. I am getting Ilegal Exception when testing in simulator.

 

/**
	 * Sends an SMS message
	 */
	public void sendSMS(final String text, final String phoneNum) {

		if (phoneNum.length() == 0) {
			Dialog.alert("Destination field cannot be blank");
		} else if (text.length() == 0) {
			Dialog.alert("Message field cannot be blank");
		} else {
			Thread thread = new Thread(new Runnable() {
				public void run() {
					try {
						System.out.println("Phone Number" + phoneNum);
						MessageConnection smsConnection = (MessageConnection) Connector
								.open("sms//+" + phoneNum);
						TextMessage message = (TextMessage) smsConnection
								.newMessage(MessageConnection.TEXT_MESSAGE);
						message.setPayloadText(text);
						smsConnection.send(message);
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			});
			thread.start();
		}

	}

 

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: illegal exception while sending a SMS

Never seen an "Illegal Exception". Can you double check the exception class?

 

Maybe "IllegalStateException"?

 

Please use plain text.
Developer
simon_hain
Posts: 16,137
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: illegal exception while sending a SMS

illegalstate would make sense as a dialog.alert without invokelater would throw one in a thread.

surround your dialog.alert with invokelater.
----------------------------------------------------------
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
Please use plain text.