tulskiy / jkeymaster

A library for registering global hotkeys in java with JNA. The goal is to support X11-based platforms, Windows and MacOSX
GNU Lesser General Public License v3.0
234 stars 45 forks source link

Swing crashes when having bad native link #19

Closed patrickballeux closed 8 years ago

patrickballeux commented 10 years ago

Hi,

I am using jKeyMaster in my project ScreenStudio (screenstudio.crombz.com). The library does work well. But I am facing one issue where I'm trying to catch the exception is some libraries are missing.

Basically, I have this case:

Using a "third-party" jna.jar instead of the native one, there is an issue between jna.jar and the libjna-java libraries. This is a case that can happen when people are not installer the proper dependencies.

What I am trying to do is to catch the error to be able to tell the user that the current setup is not working as expected and "Hot keys" won't work.

This is the exception from the console... 15-Aug-2014 10:30:46 AM com.tulskiy.keymaster.x11.X11Provider$1 run INFO: Starting X11 global hotkey provider Exception in thread "Thread-1" java.lang.UnsatisfiedLinkError: Can't obtain updateLastError method for class com.sun.jna.Native at com.sun.jna.Native.initIDs(Native Method) at com.sun.jna.Native.(Native.java:139) at com.tulskiy.keymaster.x11.X11.(X11.java:31) at com.tulskiy.keymaster.x11.X11Provider$1.run(X11Provider.java:54) at java.lang.Thread.run(Thread.java:701)

The problem is that I cannot catch the exception, coming from a thread and basically, the Swing GUI does not show making impossible showing an error message to the user.

I am using jKeymaster 1.1 binary build.

Possible solutions: Have an event "OnError" or throw an exception on the ".reset" or the ".register".

I will try to find a work-around but it would be nice if the exception would not freeze the main program.

Thanks!

tulskiy commented 10 years ago

yes, there seems to be a conflict between your system jna, and what the library is using. See https://github.com/twall/jna/issues/281

possible workaround is to pass "-Djna.nosys=true" to the java process. also, to catch this error, make sure to have catch (Throwable e) instead of catch (Exception e)

I'll try to update jna dependency to latest version, so that there is no conflict. If nothing seems to break, I'll release a new version ;)

patrickballeux commented 10 years ago

Thanks for the quick answer.

I will try that. I did found a workaround by initializing the Producer in its own thread freeing the main thread from the generated exceptions.

Would you mind if I did a screencast about your project? With ScreenStudio, I am also producing youtube videos about development and cool user friendly apps on Ubuntu. I'm always on the lookout for new ideas.

You library is so easy to use and implements. I think it's worth doing a screencast about it in my live coding sessions.

Have a great day!

Patrick Balleux

http://about.me/patrickballeux

Le 2014-08-15 à 14:23, Denis Tulskiy notifications@github.com a écrit :

yes, there seems to be a conflict between your system jna, and what the library is using. See twall/jna#281 https://github.com/twall/jna/issues/281

possible workaround is to pass "-Djna.nosys=true" to the java process. also, to catch this error, make sure to have catch (Throwable e) instead of catch (Exception e)

I'll try to update jna dependency to latest version, so that there is no conflict. If nothing seems to break, I'll release a new version ;)

— Reply to this email directly or view it on GitHub https://github.com/tulskiy/jkeymaster/issues/19#issuecomment-52340738.

tulskiy commented 10 years ago

yeah, feel free to do a screencast :)

tulskiy commented 10 years ago

could you please also try snapshot version with latest jna version? https://github.com/tulskiy/jkeymaster/blob/master/README.md#maven