Thank you DonManfred and MarkusR
Here is the SUB where I print text file and below the exception
this line throws exception second time it is executed
' start printer
Main.Printer.Initialize2(Main.BTConnection.OutputStream,"windows-1252")
Sub Print_File_BT()
Dim tr As TextReader
Dim CAMINHO As String
'Dim Printer As TextWriter
Dim Out As OutputStream
If File.ExternalWritable Then
CAMINHO = File.DirDefaultExternal
Else
CAMINHO = File.DirInternal
End If
If File.Exists(CAMINHO, "conta.txt") = False Then
Return
End If
' start printer
Main.Printer.Initialize2(Main.BTConnection.OutputStream,"windows-1252") German/French chars
Dim tr As TextReader
tr.Initialize(File.OpenInput(CAMINHO, "conta.txt"))
Dim st As String
' lê o arquivo
Do While st <> Null
st = tr.ReadLine
If st <> Null Then
Main.Printer.WriteLine(st)
End If
Loop
Main.Printer.Flush
Main.Printer.Close
Main.BTConnection.Disconnect
Msgbox(" Conta Impressa...", "")
' fecha tela
Activity.finish
End Sub
First time SUB prints file normally .. no errors
Second time I got this exception
Error occurred on line: 0 (Emite_Mostra_Conta)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug(Common.java:1036)
at iFox.PdvRest.filetransfer._zera_updateprogress(filetransfer.java:392)
at iFox.PdvRest.filetransfer._astream_newstream(filetransfer.java:303)
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:144)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336)
at anywheresoftware.b4a.debug.Debug.CallSubNew(Debug.java:282)
... 18 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
... 19 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.i
utputStream android.bluetooth.BluetoothSocket.getOutputStream()' on a null object reference
at anywheresoftware.b4a.objects.Serial.getOutputStream(Serial.java:263)
at iFox.PdvRest.emite_mostra_conta._print_file_bt(emite_mostra_conta.java:1129)
at iFox.PdvRest.emite_mostra_conta._zera_updateprogress(emite_mostra_conta.java:1286)
... 21 more