Android Question PrintPDF Error java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/print/PrintHelper;

bocker77

Active Member
Licensed User
Longtime User
I am getting this error when trying to execute the following code. It errors on the Printer.PrintPDF statement. The Android SDK is up to date. I have installed the Canon Print driver for my printer. Is there something else that I need to do? I read something about jetify something or another. I have no clue as to how to do that. Years ago in another program with a different device and printer I was able to print.

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/print/PrintHelper;
at anywheresoftware.b4a.objects.PdfDocumentWrapper$Printer.Initialize(PdfDocumentWrapper.java:119)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$1.run(BA.java:352)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:7617)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
Caused by: java.lang.ClassNotFoundException: android.support.v4.print.PrintHelper
... 15 more

B4X:
Private Sub lsvPrint_ItemClick (Position As Int, Value As Object)
    Dim y As Int
    pdf.Initialize
    If File.Exists(strPrintPath, "PrintReport.pdf") Then
        File.Delete(strPrintPath, "PrintReport.pdf")
    End If    
    out = File.OpenOutput(strPrintPath, "PrintReport.pdf", False)
    pdf.StartPage(595, 842) 'A4 size
    pdf.Canvas.DrawText(Value, 100, 100, Typeface.DEFAULT_BOLD, 11 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
    y = y + 15
    ' Create Report
    Dim lstReportMarkers As List
    lstReportMarkers.Initialize
    in = File.OpenInput(strPrintPath, Value & ".txt")
    tr.Initialize(in)
    lstReportMarkers = tr.ReadList
    tr.Close
    in.Close
    For i = 0 To lstReportMarkers.Size - 1
        strPrintMarker = lstReportMarkers.Get(i)
        pdf.Canvas.DrawText(strPrintMarker, 90, y, Typeface.DEFAULT, 11 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
        y = y + 15
        If i <> 0 And (i Mod 43) = 0 Then
            pdf.FinishPage
            pdf.StartPage(595, 842)
            y = 100
        End If
    Next
    pdf.FinishPage
    pdf.WriteToStream(out)
    pdf.Close
    out.Close    
    printer.Initialize("")
    printer.PrintPdf("Print Found Markers Report", strPrintPath, "PrintReport.pdf")
End Sub
 

bocker77

Active Member
Licensed User
Longtime User
Thanks Erel for the heads up. I imagine I can read up on the web on how to use that tool in the future if need be.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
I believe I downloaded the newest version of the Printer library from B4A website and replaced the old one that I had. Then I refreshed the libraries in the IDE. The printer library maybe part of the download and install of newer B4A versions though.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
I just looked and the version I have is 1.11 and its Path is Additional which means I had to download it. The name of the library is "Printing".
 
Upvote 0
Top