BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 01-12-2009, 06:39 AM   #1
Meenal
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: India
Model: 8700g
Carrier: Airtel
Posts: 117
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
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
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
Meenal
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: India
Model: 8700g
Carrier: Airtel
Posts: 117
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
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
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
Meenal
Thumbs Must Hurt
 
Join Date: Jan 2007
Location: India
Model: 8700g
Carrier: Airtel
Posts: 117
Default

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



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Vintage MAC Knife Japan 4.75

Vintage MAC Knife Japan 4.75" Folding Lock Blade Knife Chef Pocket Knife Utility

$224.99



Vintage MAC Tools UVEX Adjustable Safety Glasses Motorcycle Mechanic Lawnmower picture

Vintage MAC Tools UVEX Adjustable Safety Glasses Motorcycle Mechanic Lawnmower

$55.24



Vintage Mac Tools Black Frame Mirror Lens Safety Glasses USA picture

Vintage Mac Tools Black Frame Mirror Lens Safety Glasses USA

$31.88



Vintage Mac Tools USA 10” Adjustable Wrench AJC10 Forged USA picture

Vintage Mac Tools USA 10” Adjustable Wrench AJC10 Forged USA

$14.48



Vintage Mac Warehouse  3.5” Floppy Disk Solar Powered Calculator Company Swag picture

Vintage Mac Warehouse 3.5” Floppy Disk Solar Powered Calculator Company Swag

$66.60



Vintage Mac Tools AW343 Series 1/2 Pneumatic Impact Driver  picture

Vintage Mac Tools AW343 Series 1/2 Pneumatic Impact Driver

$40.00







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