Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in HIDManager.openByPath() and openById() #59

Open
GoogleCodeExporter opened this issue Mar 28, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. In 32-bit Linux, attempt to open a device when there are none plugged into 
the system. I tried both OpenJDK and Oracle JREs. The issue is not present on 
my 64-bit Windows machine.

The line:

for(HIDDeviceInfo d : devs)

throws a NullPointerException because listDevices() returns null.

I fixed the problem by changing to the source code:

public HIDDevice openById(int vendor_id, int product_id, String serial_number) 
throws IOException, HIDDeviceNotFoundException
{
    HIDDeviceInfo[] devs = listDevices();

    if(devs == null)
    {
        throw new HIDDeviceNotFoundException();
    }
    else
    {
        for(HIDDeviceInfo d : devs)
        {
            if(d.getVendor_id() == vendor_id && d.getProduct_id() == product_id && (serial_number == null || d.getSerial_number().equals(serial_number)))
                return d.open();
        }
        throw new HIDDeviceNotFoundException();
    }
}

Original issue reported on code.google.com by [email protected] on 23 Nov 2013 at 5:01

@GoogleCodeExporter
Copy link
Author

The code above works for me.
64-bit Linux (Ubuntu 14.04)
Oracle JRE 1.80_05-b13

Also had a problem with NullPointerException. But the reason wasn't a 
non-plugged HID device.
My application was not able to access the hid device. Only root may read/write 
access usb devices under linux. A udev rule in /etc/udev/rules.d was the 
solution, and grants application running as user of the group "beef" read-write 
permissions.

SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="4321", 
GROUP="beef", MODE="0664"

Original comment by [email protected] on 30 Jul 2014 at 6:25

  • Added labels: ****
  • Removed labels: ****

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant