hongweijia / javahidapi

Automatically exported from code.google.com/p/javahidapi
Other
0 stars 0 forks source link

Cannot open the device (java.lang.NullPointerException) #70

Open pooyamotorhead opened 3 weeks ago

pooyamotorhead commented 3 weeks ago

Hello I want to send reports to my USB mice . The problem is when i want to use the device object it returns null . Im sure about the vendor and product id values. About the serial number , when i read it from the device, it returned "?" for me , So i put it "null" here (i tried other values like "?" , " " , "" and so on .. but still returns null . This is the error :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "com.codeminders.hidapi.HIDDevice.enableBlocking()" because "device" is null

And here's my code :

        String serial = null;
        try {                                         
            ClassPathLibraryLoader.loadNativeHIDLibrary();

            HIDDevice device= HIDManager.getInstance().openById(20051, 21510, serial);
            try {
                device.write(CONNECT_BODY);

            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

Any suggestions would be greatly appreciated .