B4J Question [SOLVED] Printing on Linux failed

madru

Active Member
Licensed User
Longtime User
Hi,

during testing of an App on different operating systems I bumped into this error 'during printing' on Linux, the same code does work in Windows and MacOS


Error occurred on line: 76 (PrintChart)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:259)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
at b4j.example.printerjob._showprintdialog(printerjob.java:155)
at com.testprintchart._print(printchart.java:204)
at com.testprintchart._initialize(printchart.java:150)
at com.testmain$ResumableSub_Button2_Click.resume(main.java:2060)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
at jdk.internal.reflect.GeneratedMethodAccessor5.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.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:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:153)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:102)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1103)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:834)



B4X:
    Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob

    If PJ.ShowPrintDialog(Null)=False Or PJ.ShowPageSetupDialog(Null)=False Then ' This is line 76 of the code module, looks like PJ is not accessible 
        PJ.CancelJob
        Return
    End If
    
    Dim PA As Paper
    PA.Initialize()
    PA = Paper_static.A4

    Dim Pr As Printer = GetPrinter(PJ.GetPrinter.GetName)

    Dim PL As PageLayout
    PL.Initialize()
    PL = Pr.CreatePageLayout2(PA, PageOrientation_Static.LANDSCAPE, "DEFAULT")
    PJ.PrintPage2(PL, myMainForm.RootPane) 'For long way
    PJ.EndJob


any ideas?
 
Top