B4J Question Trying to use I2C on Raspberry Pi 3B, but "java.lang.reflect.InvocationTargetException" error occurred.

PierPaduan

Active Member
Licensed User
Longtime User
Hi all,
I'm trying to use I2C on GPIO of Raspberri PI 3B.
I2C interface has been enabled using raspi-config.
Actually I don't have an I2C device connected to the GPIO pins, but only an oscilloscope connected.
I'm using the code suggested by Erel here: https://www.b4x.com/android/forum/threads/iot-jpi4j-raspberry-pi-gpio-controller.37493/#content
I'm in debug mode. If I use Bus 0 I obtain Error: "java.lang.reflect.InvocationTargetException". To avoid this I changed to Bus 1 as follow and it works:
B4X:
    Dim bus As JavaObject = GetBus(1)
    Dim device As JavaObject = GetDevice(bus, 0)
    Write(device, 120)
When I get the bus I have the following WARNINGS:
B4X:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.pi4j.io.file.LinuxFile (file:/home/pi/tempjars/AsyncInput1) 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
Anyway I proceed and I get bus and device correctly, but when in the Sub Write(...) the RunMethod runs, I have this error:
B4X:
Error occurred on line: 684
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.objects.Timer$TickTack$1.run(Timer.java:118)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
    at javafx.graphics/com.sun.glass.ui.monocle.RunnableProcessor.enterNestedEventLoop(RunnableProces
sor.java:107)
    at javafx.graphics/com.sun.glass.ui.monocle.MonocleApplication._enterNestedEventLoop(MonocleApplication.java:143)
    at javafx.graphics/com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:509)
    at javafx.graphics/com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:591)
    at javafx.graphics/javafx.stage.Stage.showAndWait(Stage.java:465)
    at javafx.controls/javafx.scene.control.HeavyweightDialog.showAndWait(HeavyweightDialog.java:162)
    at javafx.controls/javafx.scene.control.Dialog.showAndWait(Dialog.java:345)
    at anywheresoftware.b4j.objects.JFX.Msgbox2(JFX.java:220)
    at anywheresoftware.b4j.objects.JFX.Msgbox(JFX.java:185)
    at b4j.example.main._appstart(main.java:260)
    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.reflec
t.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    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.start(main.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.
graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
    at javafx.graphics/com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoClassDefFoundError: sun/misc/SharedSecrets
    at com.pi4j.io.file.LinuxFile.getFileDescriptor(LinuxFile.java:215)
    at com.pi4j.io.file.LinuxFile.ioctl(LinuxFile.java:103)
    at com.pi4j.io.i2c.impl.I2CBusImpl.selectBusSlave(I2CBusImpl.java:291)
    at com.pi4j.io.i2c.impl.I2CBusImpl.runBusLockedDeviceAction(I2CBusImpl.java:258)
    at com.pi4j.io.i2c.impl.I2CBusImpl.writeByteDirect(I2CBusImpl.j
ava:169)
    at com.pi4j.io.i2c.impl.I2CDeviceImpl.write(I2CDeviceImpl.java:92)
    ... 57 more
Caused by: java.lang.ClassNotFoundException: sun.misc.SharedSecrets
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 63 more
I don't know what I'm doing wrong.
Please someone can help me fixing this error?
Thanks to everyone.
 

PierPaduan

Active Member
Licensed User
Longtime User
Hello.
Downloaded from Oracle site this file: jdk-8u241-linux-arm32-vfp-hflt.tar.gz
Copied and unpacked on Raspberry in /home/pi
Launched the bridge with:
sudo jdk1.8.0_241/bin/java -jar b4j-bridge.jar
Performed connection with B4J and Run application.
The B4J log windows says
Errore: non sono presenti i componenti runtime di JavaFX necessari per eseguire questa applicazione
Translated: "Error: there are no JavaFX runtime components needed to run this application".

If I do the same using Jdk11, the Java FX modules are loaded and I obtain the same error as yesterday.

What can I do now?
Thanks to everybody.
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
So I should create an UI app running on Java 11 and a not UI app for the I2C communication running on Java 8. Is this correct? In this case what's the correct way to exchange data between the apps?
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
With a not UI app on Java 8 I has been able to transmit and receive data with the I2C.
I will try the data exchange between app soon.
Thank you very much Erel.
 
Upvote 0
Top