首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >java代码错误(j2me)

java代码错误(j2me)
EN

Stack Overflow用户
提问于 2010-03-03 15:40:18
回答 1查看 1.2K关注 0票数 0

我得到了以下代码的异常。我不能理解什么是UUID。有人可以帮助解决这个错误吗?我已经发布了代码以及我得到的错误。

代码语言:javascript
复制
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;
}
}

错误是:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-03-03 15:48:44

您可以找到UUID here的定义。问题是您使用的UUID不合适。值“9”不起作用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2369480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档