B4J Question B4JPackager11 issue

Discussion in 'B4J Questions' started by keirS, Apr 17, 2019 at 10:27 AM.

  1. keirS

    keirS Well-Known Member Licensed User

    I get this error when trying to run a built Exe

    Code:
    class anywheresoftware.b4j.object.JavaObject (in module b4j) cannot access class sun.awt.SunToolkit (in module java.desktop) because module java.desktop does not export sun.awt to module b4j
            at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Unknown Source)
            at java.base/java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
            at java.base/java.lang.reflect.Method.invoke(Unknown Source)
            at b4j/anywheresoftware.b4j.object.JavaObject.RunMethod(Unknown Source)
            at b4j/anywheresoftware.b4j.object.JavaObject.RunMethodJO(Unknown Source)
            at b4j/uk.sensible.mtdvat.hmrcheaders._screeninfo(Unknown Source)
            at b4j/uk.sensible.mtdvat.hmrcheaders$ResumableSub_RefreshHeaders.resume(Unknown Source)
            at b4j/anywheresoftware.b4a.BA.checkAndRunWaitForEvent(Unknown Source)
            at b4j/anywheresoftware.b4a.BA.raiseEvent2(Unknown Source)
            at b4j/anywheresoftware.b4a.BA.raiseEvent(Unknown Source)
            at b4j/anywheresoftware.b4a.keywords.Common$
    3.run(Unknown Source)
            at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$
    10(Unknown Source)
            at java.base/java.security.AccessController.doPrivileged(Native Method)
            at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$
    11(Unknown Source)
            at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$
    Future.run(Unknown Source)
            at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
            at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$
    3(Unknown Source)
            at java.base/java.lang.Thread.run(Unknown Source)

    I have
    Code:
    IncludedModules: ["java.desktop"],
    in my JSON configuration file.

    ETA:

    The method called:
    Code:
    Private Sub ScreenInfo As String
        
    Dim ScreenDef As String = ""
        
    Dim ScreenWidth As String = ""
        
    Dim ScreenHeight As String = ""
        
    Dim ScreenColorDepth As String  = ""
        
    Dim JOToolKit As JavaObject
        
    Dim JOGraphicsEnvironment As JavaObject
       
        JOGraphicsEnvironment.InitializeStatic(
    "java.awt.GraphicsEnvironment")
        JOGraphicsEnvironment = JOGraphicsEnvironment.RunMethodJO(
    "getLocalGraphicsEnvironment",Null)
        JOToolKit.InitializeStatic(
    "java.awt.Toolkit")
        JOToolKit = JOToolKit.RunMethodJO(
    "getDefaultToolkit",Null)
        ScreenWidth = SU.EncodeUrl(
    "width","US-ASCII") & "="  & SU.EncodeUrl(APSU.SubstringBefore(JOToolKit.RunMethodJO("getScreenSize",Null).RunMethod("getWidth",Null),"."),"US-ASCII")
        ScreenHeight= 
    "&" & SU.EncodeUrl("height","US-ASCII") & "="  &  SU.EncodeUrl(APSU.SubstringBefore(JOToolKit.RunMethodJO("getScreenSize",Null).RunMethod("getHeight",Null),"."),"US-ASCII")
        ScreenColorDepth = 
    "&" & SU.EncodeUrl("colour-depth","US-ASCII") & "=" & SU.EncodeUrl(JOGraphicsEnvironment.RunMethodJO("getDefaultScreenDevice",Null).RunMethodJO("getDisplayMode",Null).RunMethod("getBitDepth",Null),"US-ASCII")
       
        ScreenDef = ScreenWidth & ScreenHeight & ScreenColorDepth
        
    Return ScreenDef
    End Sub
     
    Last edited: Apr 17, 2019 at 10:43 AM
  2. Erel

    Erel Administrator Staff Member Licensed User

    Edit release_java_modules.txt file that is in the Files tab of B4JPackager11. Add this to the beginning:
    --add-opens java.desktop/sun.awt=b4j
     
    keirS likes this.
  3. keirS

    keirS Well-Known Member Licensed User

    Thanks for that Erel. I have found another issue. JPOI crashes when initialized when run as an .exe

    Code:
    XML-BEANS compiled schema: Could not locate compiled schema resource schemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/index.xsb (schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.index) - code 0
    org.apache.xmlbeans.SchemaTypeLoaderException: XML-BEANS compiled schema: Could 
    not locate compiled schema resource schemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/index.xsb (schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.index) - code 0
        at b4j/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl$XsbReader.<init>(Unknown Source)
        at b4j/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.initFromHeader(Unknown Source)
        at b4j/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(Unknown Source)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
        at b4j/schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder.loadTypeSystem(Unknown Source)
        at b4j/schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder.<clinit>(Unknown Source)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unknown Source)
        at java.base/jdk.internal.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(Unknown Source)
        at java.base/jdk.internal.reflect.ReflectionFactory.newFieldAccessor(Unknown Source)
        at java.base/java.lang.reflect.Field.acquireFieldAccessor(Unknown Source)
        at java.base/java.lang.reflect.Field.getFieldAccessor(Unknown Source)
        at java.base/java.lang.reflect.Field.get(Unknown Source)
        at b4j/org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(Unknown Source)
        at b4j/org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument.<clinit>(Unknown Source)
        at b4j/org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
        at b4j/org.apache.poi.xssf.model.ThemesTable.<init>(Unknown Source)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(Unknown Source)
        at b4j/org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(Unknown Source)
        at b4j/org.apache.poi.ooxml.POIXMLDocumentPart.read(Unknown Source)
        at b4j/org.apache.poi.ooxml.POIXMLDocument.load(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at b4j/org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook(Unknown Source)
        at b4j/org.apache.poi.ss.usermodel.WorkbookFactory.createXSSFWorkbook(Unknown Source)
        at b4j/org.apache.poi.ss.usermodel.WorkbookFactory.create(Unknown Source)
        at b4j/anywheresoftware.b4j.objects.PoiWorkbookWrapper.InitializeExisting(Unknown Source)
        at b4j/b4j.example.main._btnexcel_click(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at b4j/anywheresoftware.b4a.BA.raiseEvent2(Unknown Source)
        at b4j/anywheresoftware.b4a.BA$
    1.run(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$
    10(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$
    11(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$
    Future.run(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$
    3(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)


    Code:
    Sub Process_Globals
        
    Private fx As JFX
        
    Private MainForm As Form
        
    Private Excel As PoiWorkbook
        
    Private btnExcel As Button
        
    Dim ExcelFile As FileChooser
    End Sub
    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        MainForm.RootPane.LoadLayout(
    "main")
        MainForm.Show
        ExcelFile.Initialize
    End Sub
    'Return true to allow the default exceptions handler to handle the uncaught exception.
    Sub Application_Error (Error As Exception, StackTrace As StringAs Boolean
        
    Return True
    End Sub
    Sub btnExcel_Click
        
    Dim ExcelFilename As String
        ExcelFilename = ExcelFile.ShowOpen(MainForm)
        
    If ExcelFilename.Length > 0 Then
            Excel.InitializeExisting(
    File.GetFileParent(ExcelFilename),File.GetName(ExcelFilename),""'<---- Crashes
          
        
    End If
    End Sub
    I have attached the test project.
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

    I've tried it and got a different error: java.nio.charset.UnsupportedCharsetException: Big5

    I solved it by adding this Array("jdk.charsets")

    It then worked properly.
     
  5. keirS

    keirS Well-Known Member Licensed User

    I am confused where would I add this array?

    Code:
    Excel.InitializeExisting(File.GetFileParent(ExcelFilename),File.GetName(ExcelFilename),"")
    The final parameter is the password?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    My mistake. You should add it in B4JPackager11 to IncludedModules.
     
  7. keirS

    keirS Well-Known Member Licensed User

    Did you try it with an .xls file or an xlsx file? It appears to work for .xls but not for .xlsx. I have attached the test files I am using.
     

    Attached Files:

  8. Erel

    Erel Administrator Staff Member Licensed User

    keirS likes this.
  9. Erel

    Erel Administrator Staff Member Licensed User

    Try this:

    1.
    Code:
    Private IncludedModules As List = Array("jdk.charsets")
    2. Add in line 203:
    Code:
    sb.Append("opens schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443;")
    The next line should be:
    Code:
    sb.Append("}")
    It works here tested with an unreleased version of jPOI. It is possible that more packages will need to be open like this. You need to test it.
     
    keirS likes this.
  10. keirS

    keirS Well-Known Member Licensed User

    Thanks Erel that works. I will go through testing the application tomorrow. My concern is that there may be situations where the packages are dynamically opened based on contents of the .xlsx file.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Post your findings. I want to create a short tutorial with all the information .
     
  12. keirS

    keirS Well-Known Member Licensed User

    I have found no further problems with this. Tested several worksheets with formulas on etc and it's hasn't crashed. I have not tested wring back to a sheet as the application imports data from Excel but does not save or export to Excel..
     
    Erel likes this.
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