开发者

error in java code (j2me)

开发者 https://www.devze.com 2022-12-22 04:58 出处:网络
I am getting an exception for the following 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.

I am getting an exception for the following 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.NumberFormatExceptio开发者_Go百科n
        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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消