java - 无法检测到蓝牙服务(java.lang.NumberFormatException : For input string: "0S" )

标签 java bluetooth serial-port uuid bluecove

您好,我想从我的计算机检测外部蓝牙设备的串行端口蓝牙服务,为此我使用 Bluecove API 和以下代码:

 BluetoothDeviceDiscovery bluetoothDeviceDiscovery=new BluetoothDeviceDiscovery();

        //display local device address and name
        LocalDevice localDevice = LocalDevice.getLocalDevice();
        System.out.println("Address: "+localDevice.getBluetoothAddress());
        System.out.println("Name: "+localDevice.getFriendlyName());

        //find devices
        DiscoveryAgent agent = localDevice.getDiscoveryAgent();
        UUID uuid = new UUID("SPP", true);
         String ServiceURL = agent.selectService(uuid,ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);//"btspp://localhost:"+rd.getBluetoothAddress()+";name=SPP"; 
        if( ServiceURL == null) {
            System.out.println("Connection failed: "+ uuid +"\n");
            return;
         }

但我在行中始终出现“java.lang.NumberFormatException:对于输入字符串:“0S””异常:

 UUID uuid = new UUID("SPP", true);

感谢您的帮助

最佳答案

来自bluecove的documentation

“根据提供的字符串创建 UUID 对象。字符串中的字符必须来自十六进制集 [0-9、a-f、A-F]。”

“SPP”不是有效的十六进制数字。

关于java - 无法检测到蓝牙服务(java.lang.NumberFormatException : For input string: "0S" ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8465270/

相关文章:

java - Java 中的跨平台串口通信?

java - 无法获取 JSON 对象类型数组

android - 在android中通过蓝牙进行多连接

ios - setPreferredInput WithBlueTooth 不起作用

linux - 如何在不退出 ssh session 的情况下退出 IPMI SOL session ?

c# - 拔掉USB后COM口消失

java - 使用 if 语句计算水的物质状态?

java - 持久化 JPA 域对象的良好设计

Java 等于父类(super class)和子类

ios - 可以通过 iOS 中的蓝牙 PAN 与系留设备进行通信