0

按照此处所述的说明进行操作。在我的根项目和项目类路径上的库中添加了属性文件。当我运行项目时,它会返回。

Exception in thread "main" javax.usb.UsbPlatformException: Class org.usb4java.javax.Services does not have the needed constructor
at javax.usb.UsbHostManager.initialize(UsbHostManager.java:46)
at javax.usb.UsbHostManager.getUsbServices(UsbHostManager.java:24)
at usbfinderdemo.UsbFinderDemo.main(UsbFinderDemo.java:30)

不知道可能出了什么问题。认为我可能没有使用正确的 usb4java .jar 文件,但我还不确定,因为代码根本没有显示任何错误。

代码片段

UsbServices services = UsbHostManager.getUsbServices();//the line that throws the error.
    UsbHub rootHub = services.getRootUsbHub();

    List<UsbDevice> devices = rootHub.getAttachedUsbDevices();
    if (devices.size() > 0) {
        System.out.println("USB devices found.");
    } else {
        System.out.println("No USB devices found.");
    }

    for (UsbDevice device : devices) {
        System.out.println("\tProduct String " + device.getProductString());
        System.out.println("\tManufacturer String " + device.getManufacturerString());
        System.out.println("\tSerial Number " + device.getSerialNumberString());
    }
4

0 回答 0