编译具有异常错误/警告的Java USB程序

编程入门 行业动态 更新时间:2024-10-17 02:59:30
本文介绍了编译具有异常错误/警告的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程序

本文发布于:2023-05-28 06:57:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/315152.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file &#039;D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!