B4J Question B4J + Temurin - Błąd @5b87ed94

grzegorzu78

Member
I wanted to refresh the question again because I still have problems with the proper operation of the program.
I get an error: (IllegalAccessException) java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject cannot access class com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl (in module java.xml) because module java.xml does not export com.sun.org.apache.xerces.internal.dom to unnamed module @5b87ed94


I made changes to the code as suggested in another thread, adding: #VirtualMachineArgs: --add-opens java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED

The program code looks as follows:

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
    #VirtualMachineArgs: --add-opens java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED
#End Region


I have: B4J is version 10.0. Temurin is version 21.0.3 LTS

Can anyone advise what needs to be improved?
 

grzegorzu78

Member
I am pasting the code below:
B4X:
'Class module
Sub Class_Globals
    Private xml As XMLBuilder
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    
End Sub


Public Sub Create(Par As Receipt_entity, Status As String) As String
    
    DateTime.DateFormat = "yyyy-MM-dd"
    DateTime.TimeFormat = "HHmmss"
    Dim dd As String = DateTime.Date(DateTime.now)
    Dim tt As String = DateTime.Time(DateTime.now)
    
    Try
        xml = xml.create("SOAP:Envelope")
        xml = xml.attribute("xmlns:SOAP","http://schemas.xmlsoap.org/soap/envelope/")
        xml = xml.attribute("xmlns:ser","urn:fiscal.printer.tpe/services")
        
        xml = xml.element("SOAP:Header").up
        xml = xml.element("SOAP:Body")
        xml = xml.element("ser:MsgFiscalPrinterStatus")
        xml = xml.element("MsgHeader")
        xml = xml.element("sourceSystem").text("FPS").up
        xml = xml.element("targetSystem").text("SAP").up
        'xml = xml.element("submitUser").text("xxx").up
        'xml = xml.element("submitUserEmail").text("xxx").up
        'xml = xml.element("messageId").text("99999").up
        'xml = xml.element("timeStamp").text("20170529-112427-000").up
        xml = xml.up() 'zamyka MsgHeader
        
        xml = xml.element("InvoiceNumber").text(Par.InvoiceNumber).up
        xml = xml.element("IDOCNumber").text(Par.IDOCNumber).up
        xml = xml.element("Date").text(dd).up
        xml = xml.element("Time").text(tt).up
        xml = xml.element("Status").text(Status).up
        xml = xml.up() 'zamyka ser:MsgFiscalPrinterStatus
        

        xml = xml.up() 'zamyka soap:envelop
        xml = xml.up() 'zamyka oapenv:Body
        
        Dim props As Map
        props.Initialize
        props.Put("{http://xml.apache.org/xslt}indent-amount", "4")
        props.Put("indent", "yes")
        
        'ustawia atrybut standalone
        SetStandalone(xml, True)
        props.Put("standalone", "yes")
        
        Return (xml.asString2(props))
    Catch
        Log(LastException)
        Return ""
    End Try
End Sub

Public Sub Create2(InvoiceNumber As String, IDOCNumber As String, Date As String, Time As String, Status As String) As String
    Try
        xml = xml.create("SOAP:Envelope")
        xml = xml.attribute("xmlns:SOAP","http://schemas.xmlsoap.org/soap/envelope/")
        xml = xml.attribute("xmlns:ser","urn:fiscal.printer.tpe/services")
        
        xml = xml.element("SOAP:Header").up
        xml = xml.element("SOAP:Body")
        xml = xml.element("ser:MsgFiscalPrinterStatus")
        xml = xml.element("MsgHeader")
        xml = xml.element("sourceSystem").text("FPS").up
        xml = xml.element("targetSystem").text("SAP").up
        'xml = xml.element("submitUser").text("xxx").up
        'xml = xml.element("submitUserEmail").text("xxx").up
        'xml = xml.element("messageId").text("99999").up
        'xml = xml.element("timeStamp").text("20170529-112427-000").up
        xml = xml.up() 'zamyka MsgHeader
        
        xml = xml.element("InvoiceNumber").text(InvoiceNumber).up
        xml = xml.element("IDOCNumber").text(IDOCNumber).up
        xml = xml.element("Date").text(Date).up
        xml = xml.element("Time").text(Time).up
        xml = xml.element("Status").text(Status).up
        xml = xml.up() 'zamyka ser:MsgFiscalPrinterStatus
        

        xml = xml.up() 'zamyka soap:envelop
        xml = xml.up() 'zamyka oapenv:Body
        
        Dim props As Map
        props.Initialize
        props.Put("{http://xml.apache.org/xslt}indent-amount", "4")
        props.Put("indent", "yes")
        
        'ustawia atrybut standalone
        SetStandalone(xml, True)
        props.Put("standalone", "yes")
        
        Return (xml.asString2(props))
    Catch
        Log(LastException)
        Return ""
    End Try
End Sub

Sub SetStandalone(x As XMLBuilder, b As Boolean)
    Dim joXML As JavaObject = x
    joXML.RunMethodJO("getDocument", Null).RunMethod("setXmlStandalone", Array(b))
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It looks like you will need to do the last call with inline java. It happens because the concrete class is inaccessible.

Something like:
B4X:
#if java
import org.w3c.dom.*;
public void SetStandalone(Document doc, boolean b) {
 doc.setXmlStandalone(b);
}
#end if

B4X:
Me.As(JavaObject).RunMethod("SetStandalone", Array(xml.As(JavaObject).RunMethod("getDocument", Null), b)
 
Upvote 0
Top