0
다음 코드에 대한 예외가 발생합니다. 나는 UUID가 무엇인지 이해할 수 없다. 누구든지이 오류를 해결할 수 있습니까? 나는 오류뿐만 아니라 코드를 게시했습니다.자바 코드 (j2me)의 오류
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;
}
}
오류는 다음과 같습니다
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
나는 hb ++ 인 you.what에서 제공 한 링크에서 언급 한 프로세스가 무엇이든간에 실망하지 않을 것입니까? 다른 대안이 있습니까 ??? – Ishan
링크는 UUID 정의에만 적합합니다. 9를 7C45BBBC-55C0-11D9-A188-0050BAEB61CD로 교체하십시오. 그런 다음 UUID를 직접 생성하고 동일한 것을 사용하지 않는 방법을 찾아야합니다. – kgiannakakis
다시 한번 고마워요. 나는 UUID를 생성했는데, 저도 도움이되지 않았습니다. 새 UUID가 새로 생겨나 고 Uncaught 예외가 발생했습니다 : java.lang.IllegalArgumentException : 예상치 못한 매개 변수 : 유효하지 않은 UUID – Ishan