Android Question Printing Problem

amarnath

Member
Licensed User
Longtime User
It looks ok in log file but error occurs in Printer.Write(PrintBuffer) . please help me.

this code was working fine in 2017
Object should first be initialized (TextWriter).


Printer:
Sub PrintReceipt
    startprinter

Printer.IsInitialized
'    BtAdmin.Initialize("BlueTooth")
'    BTConnection.Initialize("Printer")
    'Printer.Initialize(BTConnection.OutputStream)
'    Printer.Initialize2(BTConnection.OutputStream,"windows-1252") 'important to print f.e. German/French chars   [COLOR=rgb(226, 80, 65)]  'Here's the problem  [/COLOR]
    
'    Dim printerA As AsyncStreams
'    printerA.InitializePrefix(BTConnection.InputStream,False,BTConnection.OutputStream,"PrinterA")

    'Printer.Initialize2(BTConnection.InputStream,BTConnection.OutputStream)
    TxtCompany.Text="Amarnath"
    ' Construct the content for printing
    PrintBuffer = ""
    PrintBuffer = PrintBuffer & Chr(27) & Chr(33) & Chr(0) ' Reset settings
    PrintBuffer = PrintBuffer & "       Amarnath " & CRLF
    PrintBuffer = PrintBuffer & "       Receipt" & CRLF
    PrintBuffer = PrintBuffer & "-----------------------------" & CRLF
    PrintBuffer = PrintBuffer & "Date: " & DateTime.Date(DateTime.Now) & "  Time: " & DateTime.Time(DateTime.Now) & CRLF
    PrintBuffer = PrintBuffer & "-----------------------------" & CRLF
    
    ' Print dynamic content
    PrintBuffer = PrintBuffer & "Company: " & TxtCompany.Text & CRLF
    PrintBuffer = PrintBuffer & "FAT: " & NumberFormat(TxtFAT.Text, 1, 1) & CRLF
    PrintBuffer = PrintBuffer & "Amount: " & NumberFormat(TxtAmount.Text, 1, 2) & CRLF
    PrintBuffer = PrintBuffer & "-----------------------------" & CRLF
    PrintBuffer = PrintBuffer & "     Thank you, visit again!" & CRLF
    PrintBuffer = PrintBuffer & Chr(27) & "d" & Chr(5) ' Feed and cut
    Log(PrintBuffer)
    ' Write the buffer to printer and close connection
   [COLOR=rgb(226, 80, 65)] Printer.Write(PrintBuffer)               [B] ' Here's the problem [/B][/COLOR]
'    Printer.Flush
    xui.MsgboxAsync("Printed!", "")
 
End Sub

Error Log:
MPT-II -> 66:32:0E:71:7F:08

BlueTooth Printer -> DC:0D:30:C3:C6:FB

MPT-II -> 66:32:0E:71:7F:08

BlueTooth Printer -> DC:0D:30:C3:C6:FB



!�� Amarnath

Receipt

-----------------------------

Date: 03-11-2024 Time: 21:45:22

-----------------------------

Company: Amarnath

FAT: 2

Amount: 3

-----------------------------

Thank you, visit again!



Error occurred on line: 2294 (milkpurchaselocal)

[B][COLOR=rgb(226, 80, 65)]java.lang.RuntimeException: Object should first be initialized (TextWriter).     [/COLOR][/B]

at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)

at anywheresoftware.b4a.objects.streams.File$TextWriterWrapper.Write(File.java:568)

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:157)

at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)

at b4a.example.milkpurchaselocal._printreceipt(milkpurchaselocal.java:897)

at b4a.example.milkpurchaselocal._brnprint_click(milkpurchaselocal.java:808)

at java.lang.reflect.Method.invoke(Native Method)

at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)

at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)

at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)

at java.lang.reflect.Method.invoke(Native Method)

at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)

at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)

at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)

at android.view.View.performClick(View.java:7570)

at android.view.View.performClickInternal(View.java:7540)

at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)

at android.view.View$PerformClick.run(View.java:29721)

at android.os.Handler.handleCallback(Handler.java:942)

at android.os.Handler.dispatchMessage(Handler.java:99)

at android.os.Looper.loopOnce(Looper.java:240)

at android.os.Looper.loop(Looper.java:351)

at android.app.ActivityThread.main(ActivityThread.java:8423)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…