i wont to send message to another mobile by that code :

public void send(){
        try {
            String add = ((RemoteDevice) de.elementAt(l.getSelectedIndex())).getBluetoothAddress();
            //url = "btspp://" + add + ":" + uuid;
            url=disa.selectService(uuid,ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
            String mess = "wellcom";
            n = (StreamConnectionNotifier) Connector.open(url);
            sc=(StreamConnection)n.acceptAndOpen();
            os=sc.openOutputStream();
            os.write(mess.getBytes());
            os.close();
            sc.close();
 
            System.out.println(url);
        } catch (Exception e) {
            System.out.println(e);
        }
  
            System.out.println(url);
    
}

but i have an error that is :

Warning: To avoid potential deadlock, operations that may block, such as 
 networking, should be performed in a different thread than the 
 commandAction() handler.

plase in that time help me>>>>>>>>>>

I have never used a StreamConnection before (is that one of your classes?) but if it's anything like a ServerSocket that waits to accept() in its acceptAndOpen() method then this call needs to be made in a separate Thread. Otherwise, your main thread will sit waiting to accept and this causes a deadlock.

thank s but i cant understand so that is my code
and can you explain the solution for me

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Vector;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author home
 */
public class me2 extends MIDlet implements Runnable,DiscoveryListener,CommandListener{
    Vector de=new Vector();
     DiscoveryAgent disa;
     LocalDevice local;
     Ticker t = new Ticker("Search..........");
     int btcount;
     List l;
     String url;
     UUID uuid=new UUID("1101",true);
     StreamConnectionNotifier n;
     StreamConnection sc;
     InputStream is;
     OutputStream os;
     
      public void startApp() {
        try {
            
            l = new List("List",Choice.IMPLICIT);
            l.addCommand(new Command("Discover", Command.OK, 1));
            l.addCommand(new Command("Cancel", Command.EXIT, 1));
            l.setCommandListener(this);
            Display.getDisplay(this).setCurrent(l);
        } catch (Exception e) {
            System.out.println(e);
        }
            }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
public void send(){
        try {
            String add = ((RemoteDevice) de.elementAt(l.getSelectedIndex())).getBluetoothAddress();
            url=disa.selectService(uuid,ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
            String mess = "wellcom";
            n = (StreamConnectionNotifier) Connector.open(url);
            sc=(StreamConnection)n.acceptAndOpen();
            os=sc.openOutputStream();
            os.write(mess.getBytes());
            os.close();
            sc.close(); 
            System.out.println(url);
        } catch (Exception e) {
            System.out.println(e);
        }
}
    public void run() {
        try {
            de.removeAllElements();
            btcount=0;
            l.setTicker(t);
            local = LocalDevice.getLocalDevice();
            disa = local.getDiscoveryAgent();
            disa.startInquiry(DiscoveryAgent.GIAC, this);
        } catch (Exception e) {
            System.out.println(e);
        }        
    }
    public void deviceDiscovered(RemoteDevice bt, DeviceClass cod) {
        de.addElement(bt);
              btcount++;
    }

    public void servicesDiscovered(int t, ServiceRecord[] sr) {
       
    }

    public void serviceSearchCompleted(int arg0, int arg1) {
    
    }

    public void inquiryCompleted(int arg0) {
        if(de.isEmpty())
            l.setTicker(new Ticker("no devices found"));
        else
        l.setTicker(new Ticker("found Devices"));
            for(int i=0;i<de.size();i++){
            try {
                l.append(((RemoteDevice) de.elementAt(i)).getFriendlyName(true),null);
                //l.append(((RemoteDevice) de.elementAt(i)).getBluetoothAddress()+"\n");      
                } catch (Exception e) {
                System.out.println(e);
            }
            l.setTicker(new Ticker("found  "+btcount+"  devices"));
            disa.cancelInquiry(this);
        }
                               
    }
    public void commandAction(Command c, Displayable arg1) {
        if(c.getCommandType()==Command.OK){
        l.deleteAll();
        run();
        }
        if(c.getCommandType()==Command.EXIT){
        notifyDestroyed();
        }
        if(c==List.SELECT_COMMAND){
          l.append(((RemoteDevice) de.elementAt(l.getSelectedIndex())).getBluetoothAddress(),null);
          send();
        }
        }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.