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
Developer
Posts: 690
Registered: ‎08-09-2010
My Device: Not Specified

java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

 

public void run() {
try { 
MessageConnection msgConn = (MessageConnection) Connector.open("sms://+"+detailFields);
TextMessage text = (TextMessage) msgConn.newMessage(MessageConnection.TEXT_MESSAGE);
text.setPayloadText("Hello");
msgConn.send(text);
msgConn.close(); 
catch (Exception e)
System.out.println("Exception: " + e);
}
}

 

public void run()

{

try

MessageConnection msgConn = (MessageConnection) Connector.open("sms://+"+detailFields); TextMessage text = (TextMessage) msgConn.newMessage(MessageConnection.TEXT_MESSAGE); text.setPayloadText("Hello");

 msgConn.send(text);

 msgConn.close(); 

 

 catch (Exception e)

 System.out.println("Exception: " + e);

}

 }

 

I run this program at that time this type error "java.lang.RuntimeException: blocking operation not permitted on event dispatch thread".

so given me solution 

Developer
Posts: 374
Registered: ‎04-07-2010
My Device: Bold 9000
My Carrier: Airtel

Re: java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

[ Edited ]

Hi,

You have to Put your code in a worker thread and then call it

Follow this Link:

 

http://www.blackberryforums.com/developer-forum/170026-java-lang-runtimeexception-blocking-operation...

 

I hope it Helps...

Press the Like button (Thumb up) on the left side to thank and
please mark the Thread as solved if its solved...
K.S
Highlighted
Developer
Posts: 690
Registered: ‎08-09-2010
My Device: Not Specified

Re: java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

I have try but at that time same error coming 

 

import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;
import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.pdap.BlackBerryContact;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.UiApplication;
public class SmsScreen extends MainScreen{
EditField number;
EditField message;
EditField status;
BasicEditField detailFields = new BasicEditField();
private MenuItem send =new MenuItem("Send",111,10){
 
public void run() {
sendsms();
}
};
public SmsScreen(BlackBerryContact bbcontact ) {
super(DEFAULT_CLOSE);
setTitle(new LabelField("Create Message",USE_ALL_WIDTH));
int fieldCount, atrCount;
  
  
   VerticalFieldManager detailsList = new VerticalFieldManager();
 
   detailFields = new BasicEditField
     ("", "", 50, BasicEditField.READONLY);
 
   int fieldsWithData[] = bbcontact.getFields();
   for ( fieldCount = 0;
         fieldCount < fieldsWithData.length;
         ++fieldCount)
   {
   
     switch (fieldsWithData[fieldCount])
     {
      
       case BlackBerryContact.TEL:
         for (atrCount = 0;
              atrCount < bbcontact.countValues(BlackBerryContact.TEL);
              ++atrCount)
         {
           switch(bbcontact.getAttributes(BlackBerryContact.TEL, atrCount))
           {
            
             case BlackBerryContact.ATTR_MOBILE:
               detailFields.setText(bbcontact.getString
                 (BlackBerryContact.TEL, atrCount));
               break;
           }
         }
         break;
     }
   }
   detailsList.add(detailFields);
   add(detailsList);
   add(new SeparatorField());
   message=new EditField("Message:","");
   add(message);
   add(new SeparatorField());
   status=new EditField();
   add(status);
}
protected void makeMenu(Menu menu, int instance)
 {
 super.makeMenu(menu, instance);
 menu.add(send);
 }
protected void sendsms()
{
UiApplication.getUiApplication().invokeLater( new Runnable() {
public void run() {
try { 
MessageConnection msgConn = (MessageConnection) Connector.open("sms://+"+detailFields);
TextMessage text = (TextMessage) msgConn.newMessage(MessageConnection.TEXT_MESSAGE);
text.setPayloadText("Hello");
msgConn.send(text);
msgConn.close(); 
catch (Exception e)
System.out.println("Exception: " + e);
}
}
});
}
}

 


import javax.microedition.io.Connector;import javax.wireless.messaging.MessageConnection;

import javax.wireless.messaging.TextMessage;
import net.rim.blackberry.api.invoke.Invoke;import net.rim.blackberry.api.pdap.BlackBerryContact;import net.rim.device.api.ui.MenuItem;import net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.Dialog;import net.rim.device.api.ui.component.EditField;import net.rim.device.api.ui.component.LabelField;import net.rim.device.api.ui.component.Menu;import net.rim.device.api.ui.component.SeparatorField;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.container.VerticalFieldManager;import net.rim.device.api.ui.UiApplication;

public class SmsScreen extends MainScreen{

EditField number;

EditField message;

EditField status;

  BasicEditField detailFields = new BasicEditField();

  private MenuItem send =new MenuItem("Send",111,10){  
public void run() {

sendsms(); }

  };

 public SmsScreen(BlackBerryContact bbcontact )

{

 super(DEFAULT_CLOSE);

 setTitle(new LabelField("Create Message",USE_ALL_WIDTH));

  int fieldCount, atrCount;        

 VerticalFieldManager detailsList = new VerticalFieldManager();

     detailFields = new BasicEditField      ("", "", 50, BasicEditField.READONLY);  
   int fieldsWithData[] = bbcontact.getFields();  

 for ( fieldCount = 0;          fieldCount < fieldsWithData.length;          ++fieldCount)    {

         switch (fieldsWithData[fieldCount])  

   {       

       case BlackBerryContact.TEL:        

 for (atrCount = 0;               atrCount < bbcontact.countValues(BlackBerryContact.TEL);               ++atrCount)          {      

     switch(bbcontact.getAttributes(BlackBerryContact.TEL, atrCount))        

   {                         

 case BlackBerryContact.ATTR_MOBILE:        

       detailFields.setText(bbcontact.getString                

 (BlackBerryContact.TEL, atrCount));          

     break;        

   }        

 }        

 break;  

   }  

 }  

 detailsList.add(detailFields);  

 add(detailsList);    

add(new SeparatorField());    

message=new EditField("Message:","");  

 add(message);    

add(new SeparatorField());

     status=new EditField();  

 add(status);

 }

protected void makeMenu(Menu menu, int instance)

 {  

super.makeMenu(menu, instance);  

menu.add(send);  

}

  protected void sendsms()

{

  UiApplication.getUiApplication().invokeLater( new Runnable()

{

 public void run() {

try { 

MessageConnection msgConn = (MessageConnection) Connector.open("sms://+"+detailFields); TextMessage text = (TextMessage) msgConn.newMessage(MessageConnection.TEXT_MESSAGE); text.setPayloadText("Hello"); msgConn.send(text); msgConn.close();  catch (Exception e) System.out.println("Exception: " + e);

}

 }

});

}}

Developer
Posts: 16,750
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: java.lang.RuntimeException: blocking operation not permitted on event dispatch thread

invokelater is not a thread. use a separate thread for blocking operations.

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