gpt4 book ai didi

java - 服务器异常: The connection implementation for btspp cannot be found

转载 作者:行者123 更新时间:2023-12-01 22:47:19 24 4
gpt4 key购买 nike

我正在使用 Raspberry、bluecove-2.1.0.jar 开发蓝牙服务器
java版本“1.8.0_06”
Java(TM) SE 运行时环境(版本 1.8.0_06-b23)
Java HotSpot(TM) 客户端 VM(版本 25.6-b23,混合模式)

这里是服务器java代码:

public class BluetoothServer extends Thread {

UUID uuid = new UUID("0000110100001000800000805F9B34FB", false); // This is a magic number

String url = "btspp://localhost:" + uuid.toString() + ";name=xxxx";

Security security = new Security();

/** Constructor */

public BluetoothServer() {

}

@Override
public void run() {

waitForConnection();

}

/** Waiting for connection from devices */

private void waitForConnection() {

// retrieve the local Bluetooth device object

LocalDevice local = null;

StreamConnectionNotifier notifier = null;

StreamConnection connection = null;

// setup the server to listen for connection

try {

local = LocalDevice.getLocalDevice();

local.setDiscoverable(DiscoveryAgent.GIAC); // generally discoverable, discoveryTimeout should be disabled - but isn't.

notifier = (StreamConnectionNotifier) Connector.open(url);
// Bluetooth may go undiscoverable after 180sec default discoveryTimeout, so reset it on separate thread every 179sec.
new Timer().schedule(new TimerTask(){

@Override
public void run() {
try {
LocalDevice.getLocalDevice().setDiscoverable(DiscoveryAgent.GIAC);
} catch (BluetoothStateException e) {
System.out.println("TimerTask exception: " + e.getMessage());
e.printStackTrace();
}

}

}, 0, 179000);
} catch (Exception e) {
System.out.println("Server exception: " + e.getMessage());

e.printStackTrace();

}

// waiting for connection

while (true) {

try {

System.out.println("waiting for connection...");

connection = notifier.acceptAndOpen();

Thread processThread = new Thread(new ProcessConnectionThread(
connection, this));

processThread.start();
System.out.println("processThread.started...");
// bluetooth may have been set undiscoverable after connection
local.setDiscoverable(DiscoveryAgent.GIAC);
} catch (Exception e) {
System.out.println("Server exception: " + e.getMessage());

e.printStackTrace();

return;

}

}

}
public static void main(String[] args) {

System.out.println("Server startup now");
new BluetoothServer().start();

}

public Security getSecurity() {
return security;
}

}

当我在命令行启动服务器时:

sudo java -cp/jars:/jars/bluetoothserver.jar:/jars/bluecove-2.1.0.jar:/jars/pi4j-core.jar com.bluetoothserver.BluetoothServer
我收到此错误:

BlueCove version 2.1.0 on bluez
Server exception: The connection implementation for btspp cannot be found.
javax.microedition.io.ConnectionNotFoundException: The connection implementation for btspp cannot be found.
at javax.microedition.io.Connector.open(Connector.java:238)
at javax.microedition.io.Connector.open(Connector.java:181)
at javax.microedition.io.Connector.open(Connector.java:162)
at com.bluetoothserver.BluetoothServer.waitForConnection(BluetoothServer.java:56)
at com.bluetoothserver.BluetoothServer.run(BluetoothServer.java:32)
waiting for connection...
Server exception: null
java.lang.NullPointerException
at com.bluetoothserver.BluetoothServer.waitForConnection(BluetoothServer.java:87)
at com.bluetoothserver.BluetoothServer.run(BluetoothServer.java:32)

有什么想法吗?谢谢

最佳答案

有同样的问题。JDK 1.8.0_06 在其 rt.jar 中具有 javax.microedition.io.Connector 的实现。就我而言,解决方案是从 rt.jar 中删除 javax.microedition 包以使用 BlueCove 实现。

关于java - 服务器异常: The connection implementation for btspp cannot be found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25145168/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com