-1
我正在開發一個USB讀取Java程序來獲取連接的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
但我不確定這是否奏效。任何指針將不勝感激。