B4J Question Problem with use usb4java jar ?

bagazhou

Member
Licensed User
Longtime User
hi
i want to use libusb to devlopment my b4j program .run on windows and mac

but I don't know ,Why does it make mistakes?

libusb link: http://usb4java.org/quickstart/libusb.html

my code:
B4X:
#Region Project Attributes
  #MainFormWidth: 1000
  #MainFormHeight: 600
#End Region
#AdditionalJar: commons-lang3-3.2.1
#AdditionalJar: libusb4java-1.2.0-osx-x86.jar
#AdditionalJar: libusb4java-1.2.0-osx-x86_64.jar
#AdditionalJar: libusb4java-1.2.0-windows-x86.jar
#AdditionalJar: libusb4java-1.2.0-windows-x86_64.jar
#AdditionalJar: usb4java-1.2.0
 
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
 
Private Button1 As Button
Private Button2 As Button
Private ComboBox1 As ComboBox
Private ListView1 As ListView
Private MenuBar1 As MenuBar
Private Pane2 As Pane
Private Pane4 As Pane
Private Button3 As Button
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
MainForm.RootPane.LoadLayout("main")
 
Button1_Action
End Sub
 
Sub Button1_Action
'initial org.usb4java.LibUsb
Dim lb As JavaObject
lb.InitializeStatic("org.usb4java.LibUsb")
Log(lb.RunMethod("getVersion",Null))
Log(lb.RunMethod("getApiVersion",Null))
 
Dim drvlst As JavaObject
drvlst.InitializeStatic("org.usb4java.DeviceList")
 
Dim drv As JavaObject
drv.InitializeStatic("org.usb4java.Device")
Dim Con As JavaObject
Con.InitializeStatic("org.usb4java.Context")
Log(Con.IsInitialized)
 
' java code
' Context context = new Context();
' int result = LibUsb.init(context);
 
' problem here
Log(lb.RunMethod("init",Con))
End Sub


log:
Waiting for debugger to connect...
Program started.
1.0.18.10866
16777474
true
Error occurred on line: 61 (Main)
java.lang.ClassCastException: java.lang.Class cannot be cast to [Ljava.lang.Object;
at b4j.example.main._button1_action(main.java:135)
at b4j.example.main._appstart(main.java:85)
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)
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top