B4J Question InvocationTargetException error

Didier99

Member
Licensed User
I now regularly get this error when I recompile my project. Usually, I just recompile and the second time it goes without a hitch, like it did this time.

B4X:
Waiting for debugger to connect...
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:116)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Class.getMethod(String, java.lang.Class[])" because "<local6>" is null
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:459)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    ... 2 more
java.lang.ExceptionInInitializerError
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:495)
    at java.base/java.lang.Class.forName(Class.java:474)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.loadClass(LauncherImpl.java:383)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$3(LauncherImpl.java:422)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.RuntimeException: java.net.SocketException: Connection reset
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at b4j.can232.main.<clinit>(main.java:17)
    ... 13 more
Caused by: java.net.SocketException: Connection reset
    at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:313)
    at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:340)
    at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:789)
    at java.base/java.net.Socket$SocketInputStream.read(Socket.java:1025)
    at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:255)
    at java.base/java.io.BufferedInputStream.implRead(BufferedInputStream.java:289)
    at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:276)
    at java.base/java.io.DataInputStream.readByte(DataInputStream.java:271)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    ... 15 more

It's not a show stopper, but maybe I am doing something wrong. I have written multiple B4J apps and never seen this behavior.
 

Didier99

Member
Licensed User
Something breaks the debugger. Make some tests with other projects and see whether it is specific to this one or not.

Sometimes unexpected code in Process_Globals can cause such issues. Or it might be an over aggressive anti-virus that breaks the network connection.
Specific to this project, and on two different machines on that particular project (the project folder is under the same OneDrive folder). And if I get that error and just rebuild without any further change, it works normally.
It does it almost every time I rebuild after a change but not *every* time after a change. It is very often but I have not narrowed it down precisely what I need to do to make it do that (code change versus designer change for instance).
It's not a show stopper since so far it has always worked the second time, but I am concerned that something is broken and I may be down for good at some point if I don't fix it.

I will check older revisions of that project and try to find when it started and look for changes in Process_Global.

About anti-virus, my employer has deployed extremely invasive tools not only for anti-virus protection but also data protection against exfiltration to the point that even fairly powerful machines are getting quite slow and sometimes stop completely for a minute (no exaggeration, it's that bad, and even worse over VPN). If that keeps going, they won't have to worry about losing IP because there will not be any new IP produced...
 
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
I used to get something similar with bigger apps (more lines of code). If you search the forum for java.lang.ExceptionInInitializerError you'll find quite a few similar posts I think, but probably no definitive answer.

At times I thought it seemed to be due to the fact that I had the project files in a folder that was being backed up to OneDrive (pausing OneDrive synching seemed to help).
Clearing all breakpoints seemed to help sometimes too.
I also tried extending the process timeout (in the IDE Tools>IDE Options>Configure Process Timeout).

None of these fixed the issue entirely for me though, and I lived with it for a while until I got a new, faster PC and the issue went away :)
 
Upvote 0
Top