B4J Question pi4j question

madru

Active Member
Licensed User
Longtime User
Hi, has somebody played with pi4j recently ?

B4X:
Sub GetBus(BusNumber As Int) As JavaObject
    Dim factory As JavaObject
    Return factory.InitializeStatic("com.pi4j.io.i2c.I2CFactory").RunMethodJO("getInstance", Array As Object(BusNumber))
End Sub

returns
B4X:
java.lang.ClassNotFoundException: com.pi4jj$io$i2c$I2CFactory
 

madru

Active Member
Licensed User
Longtime User
that's what I get....

B4X:
Sub AppStart (Args() As String)
    bus = i2c.GetBus(1)
    Log(bus)
End Sub

B4X:
Sub GetBus(BusNumber As Int) As JavaObject
 
    Dim factory As JavaObject
    Return factory.InitializeStatic("com.pi4j.io.i2c.I2CFactory").RunMethodJO("getInstance", Array As Object(BusNumber))
 
End Sub

B4X:
Waiting for debugger to connect...
Program started.
Error occurred on line: 8 (i2c)
java.lang.ClassNotFoundException: com.pi4j$io$i2c$I2CFactory
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:289)
    at anywheresoftware.b4j.object.JavaObject.InitializeStatic(JavaObject.java:75)
    at b4j.example.i2c._getbus(i2c.java:39)
    at b4j.example.main._appstart(main.java:74)
    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:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja
va:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.main(main.java:29)
Program terminated (StartMessageLoop was not called).
 
Upvote 0

roberto64

Active Member
Licensed User
Longtime User
Hello, i have been trying libreia PI4J for days, but after many attempts and many tests i discover that if i use rasberry PI4 java ver.11.0.7 already installed it works, i still have to try java ver.14.0, in versions PI4J 1.2 and 1.3 give errors, I downloaded the ver.2 PI4j and I put only "pi4j-core.jar" and I remove the PI4J library the problem no longer exists, in reference to the code "B4J_LCD_BigNumber" all right up to row 56 of the lcd class with i2c call in writing it gives me this error, I have been trying for days to write in my 1602A LCD which uses "0x27" as a device, but nothing.
1 question qule java version and compatible with PI4J.
2) someone operated the LCD of the Freenova LCD 1602A kit.
3) Any help?
regards
Waiting for debugger to connect...
Program started.
AppStart :: Start
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.pi4j.io.file.LinuxFile (file:/home/pi/tempjars/AsyncInput2) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of com.pi4j.io.file.LinuxFile
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Error occurred on line: 40
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:676)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:
167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.main(main.java:29)
Caused by: java.lang.NoClassDefFoundError: sun/misc/SharedSecrets
at com.pi4j.io.file.LinuxFile.getFileDescriptor(LinuxFile.java:213)
at com.pi4j.io.file.LinuxFile.ioctl(LinuxFile.java:101)
at com.pi4j.io.i2c.impl.I2CBusImpl.selectBusSlave(I2CBusImpl.java:289)
at com.pi4j.io.i2c.impl.I2CBusImpl.runBusLockedDeviceAction(I2CBusImpl.java:256)
at com.pi4j.io.i2c.impl.I2CBusImpl.writeByteDirect(I2CBusImpl.java:167)
at com.pi4j.io.i2c.impl.I2CDevic
eImpl.write(I2CDeviceImpl.java:90)
... 20 more
Caused by: java.lang.ClassNotFoundException: sun.misc.SharedSecrets
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 26 more
 
Upvote 0
Top