【问题标题】:Server exception: The connection implementation for btspp cannot be found服务器异常:找不到 btspp 的连接实现
【发布时间】:2014-09-28 11:46:05
【问题描述】:

我正在使用 Raspberry 开发蓝牙服务器,bluecove-2.1.0.jar
java版本“1.8.0_06”
Java(TM) SE 运行时环境 (build 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)

有什么想法吗?谢谢

【问题讨论】:

    标签: java bluetooth raspberry-pi bluetooth-lowenergy bluecove


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2014-12-26
      • 2014-12-18
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 2017-06-17
      • 1970-01-01
      • 2023-03-23
      相关资源
      最近更新 更多