【问题标题】:Compiling a Java USB program with unusual errors/warnings [duplicate]编译带有异常错误/警告的 Java USB 程序 [重复]
【发布时间】:2013-04-09 05:46:56
【问题描述】:

我正在开发一个 USB 读取 Java 程序来获取连接的 USB 设备的名称。这是我写的代码:

import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.usb.*;
import javax.usb.UsbDevice;
import javax.usb.UsbDisconnectedException;
import javax.usb.UsbException;
import javax.usb.UsbHostManager;
import javax.usb.UsbHub;
import javax.usb.UsbServices;

public class ListUsbDevices {
    public static void main(String[] args) throws SecurityException, UsbException, UnsupportedEncodingException, UsbDisconnectedException {
        UsbServices services = UsbHostManager.getUsbServices();
        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());
        }
    }
}

当我编译这个程序时,它会显示这个警告:

Note: ListUsbDevices.java uses unchecked or unsafe operations.
Recompile with -Xlint:unchecked for details.

我用-Xlint:unchecked 重新编译,它显示了这个:

 ListUsbDevices.java:21: warning: [unchecked] unchecked conversion
     found   : java.util.L
     required: java.util.List<javax.usb.UsbDevice>
     List<UsbDevice> devices = rootHub.getAttachedUsbDevices();
                                          ^.

但类文件已创建。

当我运行这个程序时,我得到了这个异常:

Exception in thread "main" javax.usb.UsbException: Properties file
javax.usb.properties not found.

我该如何解决这个问题?如何在 Mac 中设置属性文件?我已经用这个设置了 CLASSPATH:

export CLASSPATH=.:/Users/sakkisetty/Documents/jsr80-1.0.1.jar

但我不确定这是否有效。任何指针将不胜感激。

【问题讨论】:

    标签: java usb compiler-warnings properties-file


    【解决方案1】:

    属性文件通常是本机包的一部分。我什至不知道 OSX 的实现。

    javax.usb FAQ 提供了如何为 Linux 设置它的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 2014-04-13
      • 2020-07-10
      • 2016-12-18
      • 1970-01-01
      相关资源
      最近更新 更多