Re: JSR82 API

Check your bluetooth settings in your pc to make sure that your pc is discoverable

Re: JSR82 API

thanks for posting the c/s example. I'm having issue with the server side giving a null pointer exception error.

java.lang.NullPointerException
- hello.btServer.<init>(), bci=21
- hello.HelloMIDlet.actionPerformed(), bci=194


I have two buttons in my Midlet to start as a client or a server. Client works fine. Server gives the above error.

when the button is clicked, I do

btServer myBTS = new btServer(this);

my class looks like this (short of all the import lines)

public class btServer {
    private HelloMIDlet parent;

    // Define the server connection URL
    String myURL = "btspp://localhost:"
                    + parent.MYSERVICEUUID_UUID.toString()
                    + ";name="+parent.myServiceName
                    + ";authenticate=false;encrypt=false;";

    // Create a server connection (a notifier)
    StreamConnectionNotifier myServer = null;
    private LocalDevice localDevice = null;
    private DiscoveryAgent discoveryAgent = null;

    public btServer(HelloMIDlet p) {
        parent = p;
   
        try {
            localDevice = LocalDevice.getLocalDevice();
            discoveryAgent = localDevice.getDiscoveryAgent();

            localDevice.setDiscoverable(DiscoveryAgent.GIAC);       
   

            myServer = (StreamConnectionNotifier)Connector.open(myURL);
            // Accept a new client connection
            StreamConnection sc = myServer.acceptAndOpen();
            DataInputStream din   = new DataInputStream(sc.openInputStream());
            while(true){
                String cmd = "";
                char c;
                while (((c = din.readChar()) > 0) && (c!='\n') ){
                    cmd = cmd + c;
                }
                parent.inform("Received " + cmd);
            }
        }
        catch (Exception  e) {
            parent.inform("Exception Occured: " + e.toString());
        }
    }
}

Any idea what I did wrong?

thanks!

Last edited by instinct (2008-10-03 21:21:05)