使用usb4java时出错

时间:2016-03-10 13:35:35

标签: java usb4java

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

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());
    }

0 个答案:

没有答案