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

Discussion in 'B4J Questions' started by Gnappos, Oct 31, 2019.

  1. Gnappos

    Gnappos Member Licensed 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


    :
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Gnappos

    Gnappos Member Licensed User

    I followed the instructions, the javac.exe file is version 11.0.1.0, maybe it is the library jreflector 1.2 library not compatible with this version?

    regards
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Best if you upload a small project that demonstrates the issue.
     
  5. Gnappos

    Gnappos Member Licensed User

    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
     
  6. Gnappos

    Gnappos Member Licensed User

    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.
     

    Attached Files:

  7. Erel

    Erel Administrator Staff Member Licensed 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.
     
    Gnappos likes this.
  8. Gnappos

    Gnappos Member Licensed User

    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.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Yes. Post the current code and we will help you change it.
     
  10. Gnappos

    Gnappos Member Licensed User

    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
     

    Attached Files:

  11. Erel

    Erel Administrator Staff Member Licensed User

    It will not be possible to use JavaObject here because 'cipher' is not a public field.
     
  12. Gnappos

    Gnappos Member Licensed User

    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.
     
  13. Daestrum

    Daestrum Well-Known Member Licensed User

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

    If you change your InitializeCipher routine to
    Code:
    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.
     
    OliverA, Erel and Gnappos like this.
  14. Gnappos

    Gnappos Member Licensed User

    Perfect it works!
    Thank you so much for your help, I still have a lot to learn.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice