编译具有异常错误/警告的Java USB程序 [英] Compiling a Java USB program with unusual errors/warnings

查看:210
本文介绍了编译具有异常错误/警告的Java USB程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was developing a USB reading Java program to get the name of the attached USB device. This is the code I wrote:

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

当我编译该程序时,它显示以下警告:

When I compile this program, it shows this warning:


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


我用 -Xlint重新编译:未选中,它显示以下内容:

I recompile with -Xlint:unchecked, and it shows this:


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


但是创建了类文件。

运行此程序时,出现以下异常:

When I run this program, I get this exception:


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


如何解决此问题?如何在Mac中设置属性文件?我已经用以下方法设置了CLASSPATH:

How do I solve this problem? How do I set the properties file in Mac? I had set the CLASSPATH with this:

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

但我不确定是否可行。

But I'm not sure that worked. Any pointers would be appreciated.

推荐答案

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

The properties file is usually part of the native package. I wasn't even aware of an implementation for OSX.

有关如何为Linux设置它的示例,请参见 javax.usb常见问题解答

An example of how to set it for Linux is available at javax.usb FAQ.

这篇关于编译具有异常错误/警告的Java USB程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆