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

Posts: 41
Registered: ‎07-19-2011
My Device: 9500
My Carrier: airtel

illegal exception while sending a SMS



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
					} catch (IOException e) {



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"?


Posts: 17,003
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

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