javax.usb.UsbException:找不到属性文件javax.usb.properties [英] javax.usb.UsbException: Properties file javax.usb.properties not found

查看:1809
本文介绍了javax.usb.UsbException:找不到属性文件javax.usb.properties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码来获取连接到系统的usb设备的manufacturerCode。我添加了jsr80-1.0.1 jar。我收到以下错误javax.usb.UsbException:

I used the following code to get the manufacturerCode of the usb device attached to the system. I added the jsr80-1.0.1 jar. And I got the following error javax.usb.UsbException:


找不到属性文件javax.usb.properties。

Properties file javax.usb.properties not found.

有任何建议吗?

import java.io.UnsupportedEncodingException;
    import java.util.*;
    import javax.usb.*;

    public class USBListener {
        public static void main(String[] args) {
            try{
                UsbServices services = UsbHostManager.getUsbServices();
                UsbHub root = services.getRootUsbHub();
                listDevices(root);
            } catch (Exception e) {
                System.out.println(e);
            }
        }

        public static void listDevices(UsbHub hub) throws UnsupportedEncodingException, UsbException {
            List devices = hub.getAttachedUsbDevices();
            Iterator iterator = devices.iterator();
            while(iterator.hasNext()) {
                UsbDevice device = (UsbDevice)iterator.next();
                describe(device);
                if(device.isUsbHub()) {
                    System.out.println("is hub");
                }
            }
        }

        public static void describe(UsbDevice device) 
            throws UnsupportedEncodingException, UsbException {
            UsbDeviceDescriptor descriptor = device.getUsbDeviceDescriptor();
            byte manufacturerCode = descriptor.iManufacturer();
            System.out.println("Manufacturer index: " + manufacturerCode);
            System.out.println("Manufacturer String: " + device.getString(manufacturerCode));
            System.out.println("USB version: " + decodeBCD(descriptor.bcdUSB()));
            System.out.println("Maximum control packet size: " + descriptor.bMaxPacketSize0());

        }

        public static String decodeBCD(short bcd) {
            int upper = (0xFF00 & bcd) >> 8;
            int middle = (0xF0 & bcd) >> 4;
            int lower = 0x0F & bcd;
            return upper + "." + middle + "." + lower;
        }
    }


推荐答案

你在你的类路径上需要这个文件。来自文档:

You need this file on your classpath. From the docs:


javax.usb.properties文件是API实现加载程序所需的
的Java属性文件类。属性文件
必须可以通过常规方式加载(即它必须在CLASSPATH中)
,并且它必须包含属性javax.usb.services。必须定义此属性
。它的值必须是实现接口javax.usb.UsbServices的
类的完全限定类名。此类
将作为javax.usb的实现加载。

The javax.usb.properties file is a Java properties file that is required by the API implementation loader class. The properties file must be loadable by normal means (i.e. it must be in the CLASSPATH) and it must contain the property javax.usb.services. This property must be defined. Its value must be the fully qualified class name of a class that implements the interface javax.usb.UsbServices. This class will be loaded as the implementation of javax.usb.

此外,如果您看到此错误,你可能没有javax.usb实现:

And further, if you are seeing this error, you presumably haven't got a javax.usb implementation:


你需要一个javax.usb实现;该文件由所有
javax.usb实现提供

You need a javax.usb implementation; the file is provided by all javax.usb implementations

见这里: http://javax-usb.sourceforge.net/faq.html#what_is_properties_file

这篇关于javax.usb.UsbException:找不到属性文件javax.usb.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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