B4J Question compiler error

drgottjr

Expert
Licensed User
Longtime User
what did i do wrong? please refer to attached screen capture:

building error:
B4J version: 4.70
Parsing code. (0.08s)
Compiling code. (0.08s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Compiling generated Java code. Error
B4J line: 46
nh.Initialize(\
javac 1.8.0_66
src\b4j\firsttest\main.java:106: error: cannot access NativeKeyListener
_nh.Initialize("nh",main.getObject());
^
class file for org.jnativehook.keyboard.NativeKeyListener not found
1 error

library manager: jNativeHookB4J (version 1.10) checked

in Process_Globals: Private nh As NativeHook

in AppStart:
nh.Initialize("nh", Me)
nh.startNativeKeyListener

from main.java:
//BA.debugLineNum = 46;BA.debugLine="nh.Initialize(\"nh\", Me)";
_nh.Initialize("nh",main.getObject());

additional libararies path is set
jNativeHookB4J.jar + .xml are in it
uh-oh.jpg
uh-oh.jpg
 

drgottjr

Expert
Licensed User
Longtime User
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
I think Erel is referring to this additional jar from https://github.com/kwhat/jnativehook/releases
thanks. i'm not seeing "b4j" in any of the versions referenced on your github link. erel's link pointed to the jnativehookb4j library (which i had already installed). i'm confused. should i replace the b4j library with one of the github versions?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
According to the link posted by Erel you need to download the version 2.02 of jNativeHook from the link above , as well as have the jNativeHookB4J library in the libraries folder.
jNativeHookB4J relies on the jNativeHook.jar

From Erels link
In order to use this library, download the JNativeHook-<version>.zip file from this address: https://github.com/kwhat/jnativehook/releases . The B4J library was written for version 2.0.2. Unzip the archive and place the JNativeHook.jar file in your B4J external libraries folder.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
I think Erel is referring to this additional jar from https://github.com/kwhat/jnativehook/releases

see it now, thanks. how does app know it needs it/where to find it? "#additionalJar:", perhaps? "additional libraries", perhaps? "b4j/libraries", perhaps? i tried them all, still getting error. jnativehook.jar now sitting in several locations in effort to cover all bases. compiler still not seeming to find it...
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
ok - just tried it
you have to rename the jnativehook-2.0.2.jar to jnativehook.jar and place it in your additional libraries folder.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
rename does it, thanks. (that is to say, it compiles.)

when i build and it runs and i shut it down right away i get:
java.lang.NoSuchMethodException: b4j.firsttest.main._nh_unregistered()
which may or may not be an entirely different matter...

fyi, in eventname_closerequest and mainform_closed subs i unregister the listener (per lib author's recommendation). maybe i have it in the wrong place? or maybe the listener didn't start listening?

i wanted to try your suggestion immediately to see if it addressed the compiler error, so i haven't put the application through its paces, but i am concerned about the latest exception.

-go
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
did you call
B4X:
nh.endNativeKeyListener
before you try to unregister it ?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
It appears that if you close the mainform, then in MainForm_Closed you end the listener then unregister it , you must have a sub called ??.Unregistered
ie,
B4X:
Sub nh_Unregistered
 Log("unregistered hook")
End Sub
If I don't have the sub, when I close the mainform window (and end and unregister the listener in the closed sub) I get exactly the same error you had.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
It appears that if you close the mainform, then in MainForm_Closed you end the listener then unregister it , you must have a sub called ??.Unregistered
ie,
B4X:
Sub nh_Unregistered
Log("unregistered hook")
End Sub
If I don't have the sub, when I close the mainform window (and end and unregister the listener in the closed sub) I get exactly the same error you had.

works for me too! thanks. now i have to see if the whole damn listener does what it's supposed to do: i need to intercept the paste part of copy from/paste to the clipboard to massage the captured text before the paste occurs. thanks again

-go
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Yes, as explained in the comments in the library, the _Unregistered event is raised when you unregister the NativeHook. This is because the NativeHook runs in its own thread with its own message loop. If the NativeHook's message loop is the last running message loop in the program and all other threads have ended, then ending the NativeNook message loop will kill your program. Adding the _Unregistered event allows you (the programmer) to gracefully handle the program ending.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Yes, as explained in the comments in the library, the _Unregistered event is raised when you unregister the NativeHook. This is because the NativeHook runs in its own thread with its own message loop. If the NativeHook's message loop is the last running message loop in the program and all other threads have ended, then ending the NativeNook message loop will kill your program. Adding the _Unregistered event allows you (the programmer) to gracefully handle the program ending.

thank. the call is safely in place now.
 
Upvote 0
Top