BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 01-12-2009, 06:39 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: India
Model: 8700g
Carrier: Airtel
Posts: 117
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

Please Login to Remove!

I have written the following code where on listening to a key event, the following code is executed.

Code:
public boolean keyRepeat(int keycode, int time) {
       
                try {
                    count = 0;
                    UiApplication.getApplication().removeKeyListener(this);
                    System.out.println("Sending SMS .... ");
                    MessageConnection conn = null;
                    TextMessage text = null;
                    String message = "Hello ... this is a test msg";
                    conn = (MessageConnection) Connector.open("sms://" + phNumbers);
                    text = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
                    text.setPayloadText(message);
                    conn.send(text);
                    conn.close();
                } catch (Exception ex) {
                    System.out.println("Excemtion: " + ex.toString());
                }
    }
But i get following error @ conn.send(text):
java.lang.RuntimeException: blocking operation not permitted on event dispatch thread.

Any idea why this is happening.
__________________
Thanks
Meenal
Offline  
Old 01-12-2009, 08:21 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

You cannot perform a blocking operation from the UI event thread (like this SMS activity). You'll need to handle these operations in a worker thread.
Offline  
Old 01-12-2009, 08:35 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: India
Model: 8700g
Carrier: Airtel
Posts: 117
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried sending the sms through a new thread ... but stil its the same. :(
following is my code:

Code:
try {
            count = 0;
            UiApplication.getApplication().removeKeyListener(this);
            System.out.println("Sending SMS .... ");
            SendSMS sms = new SendSMS("Hello ..... this a test message.");
            sms.run();
        } catch (Exception ex) {
            System.out.println(ex.toString());
        }
where SendSMS is the class used to send SMS:

Code:
public class SendSMS extends Thread {
    MessageConnection conn = null;
    TextMessage text = null;
    String message;
    public SendSMS(String msg){
        message = msg;
    }
    public void run() {
        try {
            conn = (MessageConnection) Connector.open("sms://+1234567890");
            text = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
            text.setPayloadText(message);
            conn.send(text);
            conn.close();
        } catch (IOException e) {
            System.out.println("Exception: " + e);
        }
    }
   
}
but i am having the same error :( ??
__________________
Thanks
Meenal
Offline  
Old 01-12-2009, 08:54 AM   #4 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

you have to use start() to start a thread, not run().
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 01-13-2009, 12:15 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: India
Model: 8700g
Carrier: Airtel
Posts: 117
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx Simon .... i knew i was doing something stupid.
__________________
Thanks
Meenal
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.