B4J Question Where to put .dll used in LoadLibary() in library?

alwaysbusy

Expert
Licensed User
Longtime User
I'm writing a library that uses an external dll (ThinkGear.dll). In the eclipse library it is used as:

static { System.loadLibrary("thinkgear"); }

No problems so far. When I now run it, I'll get the following error:

B4X:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: no thinkgear in java.library.path
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
    at b4j.example.main.<clinit>(main.java:16)
Caused by: java.lang.UnsatisfiedLinkError: no thinkgear in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1088)
    at com.AB.ABThinkGear.ABThinkGear.<clinit>(ABThinkGear.java:12)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:451)
    at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:438)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:239)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    ... 2 more
Exception in thread "main"

Makes sense, I haven't put the dll anywhere. I would suspect it needs to be in the \B4J\Objects\shell\bin\classes\b4j\example folder. I made it read only, but then I can't compile the project anymore.

b4jerror1.png



Is there a special folder I can use?

Cheers,

Alain
 

alwaysbusy

Expert
Licensed User
Longtime User
Closer, but no sigar!

I can compile, but not run:

B4X:
Program started.
java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: com.AB.ABThinkGear.ABThinkGear.TG_GetDriverVersion()I
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.start(main.java:35)
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.UnsatisfiedLinkError: com.AB.ABThinkGear.ABThinkGear.TG_GetDriverVersion()I
    at com.AB.ABThinkGear.ABThinkGear.TG_GetDriverVersion(Native Method)
    at com.AB.ABThinkGear.ABThinkGear.GetDriverVersion(ABThinkGear.java:95)
    at b4j.example.main._appstart(main.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:558)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:224)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    ... 14 more

Attached is the B4J project and the java library project. In my view, this should be a very simple 'wrap'. The GetDriverVersion() function shuold work without having the hardware. I did this wrapper in Xojo (using declares) but thought this could be a grood project to test out B4J :)

Cheers,

Alain
 

Attachments

  • ABThinkGear.zip
    180.7 KB · Views: 288
  • ABThinkGearLib.zip
    9.4 KB · Views: 293
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
I found several versions around. I think this one is based on the Official SDK of NeuroSky.

Here are some versions I have:

ThinkGear1: using jna to access the dll (could not get it working as it had problems finding the jna lib)
ThinkGear2: The official one I based mine on
ThinkGearSocket3: The one using sockets (like you suggested), written for Processing (is java like)

I was just trying it out like this at it seemed straightforward (and very similar to use as the xojo one). But I guess I will have to try to get a go with the third option anyway.
 

Attachments

  • ThinkGearJava.zip
    10.4 KB · Views: 284
Upvote 0

Thuong

Member
Licensed User
Longtime User
Dear
I code static { System.load("/thinkgear.dll"); } and compile is ok to B4A library
It is correct ?
 
Upvote 0
Top