Hi, I use a TextWriter object to send data to a printer, but I get the following error when I try to connect it:
but the TextWriter has to be initialized after the bluetooth serial connection is established. How can I fix this error?
My code:
B4X:
java.lang.RuntimeException: Object should first be initialized (TextWriter)
but the TextWriter has to be initialized after the bluetooth serial connection is established. How can I fix this error?
My code:
B4X:
Sub Process_Globals
Dim BTSerialPrinter As Serial
Dim PrinterWriter As TextWriter
End Sub
Sub Globals
Dim BTPortPrinter As Int
Dim BTMacPrinter As String
End Sub
Sub Activity_Create (FirstTime As Boolean)
If (FirstTime = True) Then
BTSerialPrinter.Initialize("BTSerialPrinter")
End If
End Sub
Sub ButtonConnectBTPrinter_Click
BTMacPrinter = (printer mac address)
BTPortPrinter = 1
BTSerialPrinter.Connect3(BTMacPrinter,BTPortPrinter)
End Sub
Sub BTSerialPrinter_Connected (Success As Boolean)
If (Success = True) Then
PrinterWriter.Initialize(BTSerialPrinter.OutputStream)
Else
If BTPortPrinter < 10 Then
BTPortPrinter = BTPortPrinter + 1
BTSerialPrinter.Connect3(BTMacPrinter,BTPortPrinter)
End If
End If
End Sub