B4J Question How to call third party jar use javaobject by parameters?

bagazhou

Member
Licensed User
Longtime User
HI

this problems is, i calling third party jar by RunMethodJO,How to use javaobject by parameters? thanks !

B4X:
jave code:
Context useCtx = null; 
useCtx = new Context();
                     
Device usbDev = null;
usbDev = Device.search(useCtx, 1000, 200); 


b4j code:
Dim useCtx  As JavaObject
useCtx  = useCtx .InitializeNewInstance("ch.ntb.inf.libusb.Context",Null)
Log("useCtx .IsInitialized:" & useCtx .IsInitialized)

Dim usbDev As JavaObject
usbDev.InitializeStatic("ch.ntb.inf.libusb.Device")
' this line is error
usbDev.RunMethodJO("search",Array (useCtx, 1000,200 ))


error message:
java.lang.reflect.InvocationTargetException
 

bagazhou

Member
Licensed User
Longtime User
Thank you for your reply. this my full code and error message

Class Device
  • java.lang.Object
    • ch.ntb.inf.libusb.Device
Method Summary
static Device open(Context ctx, int vid, int pid)
open device with following parameters

B4X:
#Region Project Attributes
    #MainFormWidth: 800
    #MainFormHeight: 500
#End Region  
'   #AdditionalJar: usb-api-1.0.2
'   #AdditionalJar: usb4java-javax-1.2.0
  
   #AdditionalJar: LibusbJava
  
  
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form

End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    MainForm.RootPane.LoadLayout("main")

'   jave code:
'   Context useCtx = null;
'   useCtx = new Context();
    Dim useCtx  As JavaObject
    useCtx  = useCtx .InitializeNewInstance("ch.ntb.inf.libusb.Context",Null)
    Log("useCtx .IsInitialized:" & useCtx .IsInitialized)

'   jave code:
'   Device usbDev = null;
    Dim usbDev  As JavaObject
    usbDev = usbDev.InitializeStatic("ch.ntb.inf.libusb.Device")
    Log("usbDev.IsInitialized:" & usbDev.IsInitialized)
    Log("usbDev.getNofDevices:" & usbDev.RunMethod("getNofDevices",Null))

'   jave code:
'   usbDev = Device.search(useCtx, 1000, 200);
    usbDev.RunMethodJO("search",Array (useCtx, 100,200 ))   ' this line is error

End Sub


B4X:
Waiting for debugger to connect...
Program started.
useCtx .IsInitialized:true
usbDev.IsInitialized:true
usbDev.getNofDevices:0
Error occurred on line: 40 (Main)
java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
   at anywheresoftware.b4j.object.JavaObject.RunMethodJO(JavaObject.java:138)
   at b4j.example.main._appstart(main.java:101)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
   at b4j.example.main.start(main.java:38)
   at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
   at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
   at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
   at java.security.AccessController.doPrivileged(Native Method)
   at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
   at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
   at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
   at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
   at java.lang.Thread.run(Thread.java:745)
Caused by: ch.ntb.inf.libusb.exceptions.NoDeviceException
   at ch.ntb.inf.libusb.Device.search(Device.java:72)
   ... 31 more
 
Upvote 0
Top