views:

294

answers:

1

hello. i am gettin an exception for the followwing code.i am not able to understand what is UUID,can anyone help to resolve this error.i have posted the code as well as error,i am getting.

package wiki.nokia.example;

import java.io.IOException;
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.L2CAPConnection;
import javax.bluetooth.L2CAPConnectionNotifier;
import javax.bluetooth.LocalDevice;
import javax.microedition.io.Connector;

public class BluetoothServer implements Runnable {

private boolean listening = true;
private LocalDevice local_device;
private BtoothChat midlet;
private String deviceName;
private L2CAPConnection con;

/** Creates a new instance of BluetoothServer */
public BluetoothServer(BtoothChat midlet) {
this.midlet = midlet;
Thread t = new Thread(this);
t.start();
}

public void run(){
System.out.println("Starting server - please wait...");

try {
local_device = LocalDevice.getLocalDevice();
DiscoveryAgent disc_agent = local_device.getDiscoveryAgent();
local_device.setDiscoverable(DiscoveryAgent.LIAC);
String service_UUID = "9";
deviceName = local_device.getFriendlyName();
String url = "btl2cap://localhost:" + service_UUID + ";name=" + deviceName;

L2CAPConnectionNotifier notifier = (L2CAPConnectionNotifier)Connector.open(url);
con = notifier.acceptAndOpen();

while (listening) {
if (con.ready()){
byte[] b = new byte[1000];
con.receive(b);
String s = new String(b, 0, b.length);
System.out.println("Recieved from client: " + s.trim());
midlet.setAlert(s.trim());
send("Hello client, my name is: " + getName());
listening=false;
}
}

} catch(BluetoothStateException e){System.out.println(e);} catch(IOException f){System.out.println(f);}
}
private void send(String s){
byte[] b = s.getBytes();
try {
con.send(b);
} catch(IOException e){
System.out.println(e);
}
}
private String getName(){
return deviceName;
}
}

ERROR IS:

Starting server - please wait...
Uncaught exception: java.lang.NumberFormatException
        at java.lang.Long.parseLong(Long.java:401)
        at javax.bluetooth.UUID.<init>(), bci=166
        at com.sun.jsr082.bluetooth.btl2cap.L2CAPNotifierImpl.createServiceRecord(), bci=26
        at com.sun.jsr082.bluetooth.btl2cap.L2CAPNotifierImpl.<init>(), bci=122
        at com.sun.jsr082.bluetooth.btl2cap.Protocol.serverConnection(), bci=16
        at com.sun.jsr082.bluetooth.BluetoothProtocol.openPrimImpl(), bci=24
        at com.sun.jsr082.bluetooth.BluetoothProtocol.openPrim(), bci=14
        at com.sun.midp.io.j2me.btl2cap.Protocol.openPrim(), bci=7
        at javax.microedition.io.Connector.openPrim(), bci=327
        at javax.microedition.io.Connector.open(), bci=3
        at javax.microedition.io.Connector.open(), bci=3
        at javax.microedition.io.Connector.open(), bci=2
        at wiki.nokia.example.BluetoothServer.run(BluetoothServer.java:48)
        at java.lang.Thread.run(), bci=11
A: 

You can find a definition of an UUID here. The problem is that the UUID you are using isn't appropriate. A value of '9' won't do.

kgiannakakis
i din't undesrstand what process they have mentioned on the link which has been provided by you.what is hb++?is there any other alternative???
The link is only good for the definition of an UUID. Try replacing 9 with 7C45BBBC-55C0-11D9-A188-0050BAEB61CD. Then, you need to find a way to generate an UUID yourself and not use the same one all the time.
kgiannakakis
Thank you once again,i generated UUID,that did not help either.Everytime i am getting new new UUID's and the error comes as Uncaught exception: java.lang.IllegalArgumentException: unexpected parameter: invalid UUID
Look up the javax.bluetooth documentation to see how the UUID should be generated and what is the appropriate format.
kgiannakakis