B4J Question Java Error when exporting to Excel

AKJammer

Active Member
Licensed User
Could someone decipher this java log? My project works fine in debug mode, but when I put into release mode and package it up as an exe file with B4JPackager11 and click my 'Export data to Excel' button, it blows up.

If this log isn't definitive enough, I'll build a simple project that highlights the error. It appears I'm just missing a library in the packager, but if I try adding the jPOI library module I get warnings saying it's not being used, and it still blows up...

Thanks!

B4X:
Clicked RegType
Diagnostic XML Bean debug log file created: C:\Users\Jim\AppData\Local\Temp\xmlbeandebug10191676254534018280.log
impexp._exportexcel (java line: -1)
java.lang.ExceptionInInitializerError
        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.spreadsheetml.x2006.main.CTWorkbook.<clinit>(Unknown Source)
        at b4j/org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.newInstance(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
        at b4j/anywheresoftware.b4j.objects.PoiWorkbookWrapper.InitializeNew(Unknown Source)
        at b4j/b4j.example.impexp._exportexcel(Unknown Source)
        at b4j/b4j.example.impexp._btnexport_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)
Caused by: java.lang.RuntimeException: Could not instantiate SchemaTypeSystemImpl (java.lang.reflect.InvocationTargetException): is the version of xbean.jar correct?
        at b4j/schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder.loadTypeSystem(Unknown Source)
        at b4j/schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder.<clinit>(Unknown Source)
        ... 35 more
Caused by: java.lang.reflect.InvocationTargetException
        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)
        ... 37 more
Caused by: 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)
        ... 41 more
 

Chris2

Active Member
Licensed User
Longtime User
You'll need
B4X:
Private IncludedModules As List = Array("jdk.charsets")
in the Process_Globals of B4JPackager11 too.
 
Upvote 0

AKJammer

Active Member
Licensed User
Thanks Chris,
Reading the other posts, that is definitely the correct track. I'm not really a Java person, so not sure what a JSON file would be in my case, but I've made these corrections.

1. I was using an older Packager version. Pulled down latest and am using 1.13 of B4JPackager11 now.
2. Added these lines in the Process_Globals area:
B4X:
Sub Process_Globals
   Private InputJar As String = "D:\B4J_Dev\Projects\Main\Objects\MMMain.jar"
   Private IconFile As String = "D:\B4J_Dev\Projects\Main\Files\mtmagiclogo.ico"
   Private NetFrameworkCSC As String = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" 'windows only

   'Need these next two lines for POI Excel
   Private AdditionalModuleInfoString As String = "opens schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443;"
   Private IncludedModules As List = Array("jdk.charsets")
   
   Private ExcludedModules As List
   ExcludedModules = Array("javafx.web") 'comment this line if using WebView

Unfortunately I'm still bombing on the Excel creation:

B4X:
Clicked RegType
Diagnostic XML Bean debug log file created: C:\Users\Jim\AppData\Local\Temp\xmlbeandebug13420617710013865282.log
impexp._exportexcel (java line: -1)
java.lang.ExceptionInInitializerError
        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.spreadsheetml.x2006.main.CTWorkbook.<clinit>(Unknown Source)
        at b4j/org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.newInstance(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
        at b4j/org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
        at b4j/anywheresoftware.b4j.objects.PoiWorkbookWrapper.InitializeNew(Unknown Source)
        at b4j/b4j.example.impexp._exportexcel(Unknown Source)
        at b4j/b4j.example.impexp._btnexport_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)
Caused by: java.lang.RuntimeException: Could not instantiate SchemaTypeSystemImpl (java.lang.reflect.InvocationTargetException): is the version of xbean.jar correct?
        at b4j/schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder.loadTypeSystem(Unknown Source)
        at b4j/schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder.<clinit>(Unknown Source)
        ... 35 more
Caused by: java.lang.reflect.InvocationTargetException
        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)
        ... 37 more
Caused by: 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)
        ... 41 more
 
Upvote 0

AKJammer

Active Member
Licensed User
Hmmm, nope. Line 203 is sb.Initialize so I added the "opens " line right after that but the packager doesn't like the syntax.

I tried adding it at different points, but it's continuing to error on the build.

arghh!
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
Hmmm, nope. Line 203 is sb.Initialize so I added the "opens " line right after that but the packager doesn't like the syntax.

I tried adding it at different points, but it's continuing to error on the build.

arghh!

It should look like:

B4X:
Private Sub CreateModuleFile As ResumableSub
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append($"module ${TargetModule} {"$).Append(CRLF)
    For Each Module In Modules
        sb.Append("requires ").Append(Module).Append(";").Append(CRLF)
    Next
    sb.Append("exports ").Append(PackageName).Append(";").Append(CRLF)
    If File.Exists(TempFolder, ReplaceSlashes("META-INF\services")) Then
        For Each f As String In File.ListFiles(File.Combine(TempFolder, ReplaceSlashes("META-INF\services")))
            sb.Append("uses ").Append(f).Append(";").Append(CRLF)
        Next
    End If
    sb.Append("opens schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443;")
    sb.Append("}")
    File.WriteString(TempFolder, "module-info.java", sb.ToString)
    Dim args As List = Array($"--patch-module"$, $"${TargetModule}=jar.jar"$, "-p", Q(JavaFXLibs), "module-info.java")
    Wait For (RunShell(False, "javac", args)) Complete (StdOut As String)
    Wait For (RunShell(False, "jar", Array("-uf", "jar.jar", "module-info.class"))) Complete (Output As String)
    Return True
End Sub
 
Upvote 0

AKJammer

Active Member
Licensed User
Thanks Keir,

That did it. I was putting the opens line above the exports. Everything is working now.

Thanks everyone!!

Jim
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is not needed if you are using the latest version.

The code is:
B4X:
Private Sub CreateModuleFile As ResumableSub
   Dim sb As StringBuilder
   sb.Initialize
   sb.Append($"module ${TargetModule} {"$).Append(CRLF)
   For Each Module In Modules
       sb.Append("requires ").Append(Module).Append(";").Append(CRLF)
   Next
   sb.Append("exports ").Append(PackageName).Append(";").Append(CRLF)
   If File.Exists(TempFolder, ReplaceSlashes("META-INF\services")) Then
       For Each f As String In File.ListFiles(File.Combine(TempFolder, ReplaceSlashes("META-INF\services")))
           If f.Contains("$") = False Then
               sb.Append("uses ").Append(f).Append(";").Append(CRLF)
           End If
       Next
   End If
   sb.Append(AdditionalModuleInfoString) '<-------------------------------------------------------
   sb.Append("}")
   File.WriteString(TempFolder, "module-info.java", sb.ToString)
   Dim args As List = Array($"--patch-module"$, $"${TargetModule}=jar.jar"$, "-p", Q(JavaFXLibs), "module-info.java")
   Wait For (RunShell(False, "javac", args)) Complete (StdOut As String)
   Wait For (RunShell(False, "jar", Array("-uf", "jar.jar", "module-info.class"))) Complete (Output As String)
   Return True
End Sub

You only need to set the value of AdditionalModuleInfoString.
 
Upvote 0

AKJammer

Active Member
Licensed User
And that works as well after I removed the second initialization of the variable from the Process_Globals area. I hadn't seen that there were already variables there. I'm now up and working. Thanks again.

Jim
 
Upvote 0
Top