B4J Question after B4J update: java.lang.NoClassDefFoundError at Dim r As Reflector

Status
Not open for further replies.

Gnappo jr

Active Member
Licensed User
Longtime User
Hello everybody
I have a program in B4j that worked great and uses the jreflector 1.2 library
after updating B4J to version 7.80 I get a java.lang.NoClassDefFoundError error to this
code line: 85 Dim r As Reflector

If in the path I use jdk1.8.0_91 .... javac.exe instead of the recent jdk-11.0.1 ..... javac.exe, the program returns to work without error

Error:
java.lang.NoClassDefFoundError: javafx/event/EventHandler
at b4j.example.webservice1._initializecipher(webservice1.java:139)
at b4j.example.webservice1._decrypt(webservice1.java:102)
at b4j.example.webservice1._handle(webservice1.java:267)
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.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
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 anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:130)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:119)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
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.ClassNotFoundException: javafx.event.EventHandler
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)
... 31 more


:
 

Gnappo jr

Active Member
Licensed User
Longtime User
Best if you upload a small project that demonstrates the issue.
I prepared a small program deriving from the main one to repeat the problem, ... but the problem does not occur!
In the big program (a webserver that works with another app) everything works with java jdk1.8.0_91.
I will try to isolate the problem in a few lines of code and provide for uploading.
Thanks for the support
 
Upvote 0

Gnappo jr

Active Member
Licensed User
Longtime User
Best if you upload a small project that demonstrates the issue.

I have prepared two small projects that demonstrate the problem:

The file Test0.zip shows that the program goes into error by selecting C: Program Files Java jdk-11.0.1 bin javac.exe,
instead select C: Program Files Java jdk1.8.0_91 bin javac.exe perfectly.

The File Test1.zip identical to the previous one, differs in the fact that it is equipped with a user interface (winform and label) but it works with both versions of java.
 

Attachments

  • test0.zip
    29.9 KB · Views: 294
  • Test1.zip
    84.7 KB · Views: 303
Upvote 0

Gnappo jr

Active Member
Licensed User
Longtime User
It happens because jReflector references a class that is part of JavaFX. Starting from Java 11 the JavaFX classes are separated from the JRE and are only available in UI apps.

You can use JavaObject instead.
Erel, you are magnificent!
I tried to replace jReflector with JavaObject but without success (of course). Unfortunately I do not have adequate knowledge to be able to modify the statements relating to jReflection and replace them with equivalents in javaObject. Do you think it is appropriate to open a new therad to get support for this?
Thanks anyway for revealing the mystery.
 
Upvote 0

Gnappo jr

Active Member
Licensed User
Longtime User
Yes. Post the current code and we will help you change it.

The complete code is the one present in the file Test0.zip already posted previously, the console application not UI

Sub InitializeCipher(c As Cipher, transformation As String)
'Log(C.GetServices)
Dim r As Reflector
Dim o As Object = r.RunStaticMethod("javax.crypto.Cipher", "getInstance", Array(transformation,"BC"), Array As String("java.lang.String", "java.lang.String"))
r.Target = c
r.SetField2("cipher", o)
End Sub


Any suggestion is well appreciated.
Thanks again
 

Attachments

  • test0.zip
    29.9 KB · Views: 287
Upvote 0

Gnappo jr

Active Member
Licensed User
Longtime User
It will not be possible to use JavaObject here because 'cipher' is not a public field.
Forgive me, Erel, but I didn't understand the limitation of JavaObject with non-public fields, patience.

Now I am faced with two choices:

1. continue to use the code with the obsolete jdk1.8.0_91 and continue like this over time

2. completely modify the method of data encryption, giving an app b4j and a b4a so that you can use the official Java jdk-11.0.1, in the latter case what is a really working method for exchanging encrypted http data between app b4a and b4j?
I apologize for the insistence, but I believe that this can also be useful to others.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I must say I am confused as to why you are using jReflector in your code.

If you change your InitializeCipher routine to
B4X:
Sub InitializeCipher(c As Cipher, transformation As String)
 c.Initialize(transformation)
End Sub

The encoded string is decoded properly. (this also works in java 11)
select incrocio from incroci inner join dati_net on CAST(valore as varchar(25))=ean_code where etichetta like '40'
Of course I could have completely missed the point of this thread.
 
Upvote 0

Gnappo jr

Active Member
Licensed User
Longtime User
I must say I am confused as to why you are using jReflector in your code.

If you change your InitializeCipher routine to
B4X:
Sub InitializeCipher(c As Cipher, transformation As String)
 c.Initialize(transformation)
End Sub

The encoded string is decoded properly. (this also works in java 11)

Of course I could have completely missed the point of this thread.
Perfect it works!
Thank you so much for your help, I still have a lot to learn.
 
Upvote 0

Jim McDougal

Member
Licensed User
I'm trying to run Forms Builder in B4J with Java\jdk-11.0.1\bin\javac.exe and I get the following error response:

Main - 67: Undeclared variable 'r' is used before it was assigned any value.
Main - 66: Undeclared variable 'r' is used before it was assigned any value.
Main - 65: Unknown type: reflector
Are you missing a library reference?

And the error in:

Sub AddKeyPressedListener
Dim r As Reflector
r.Target = MainForm.RootPane
r.AddEventHandler("keypressed", "javafx.scene.input.KeyEvent.KEY_PRESSED")
End Sub

Any thoughts on what might be causing this? Both B4J and Forms Builder were downloaded from B4X website today.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Forms Builder in B4J
The Form builder is deprecated for years now.

Use the internal Designer.

Away from that you shouild create A NEW THREAD FOR EACH QUESTION you have. Posting to old threasds is a mistake.
 
Upvote 0
Status
Not open for further replies.
Top