what caused this error?
lastexception
full error logs when i remove try catch
code
lastexception
(NullPointerException) java.lang.NullPointerException: Attempt to invoke virtual method 'java.iutputStream android.bluetooth.BluetoothSocket.getOutputStream()' on a null object reference
full error logs when i remove try catch
java.lang.NullPointerException: Attempt to invoke virtual method 'java.iutputStream android.bluetooth.BluetoothSocket.getOutputStream()' on a null object reference
at anywheresoftware.b4a.objects.Serial.getOutputStream(Serial.java:261)
at b4a.G8.STLSK.main._pe_smssentstatus(main.java:2675)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.phone.PhoneEvents$ActionHandler.send(PhoneEvents.java:326)
at anywheresoftware.b4a.phone.PhoneEvents$10.handle(PhoneEvents.java:188)
at anywheresoftware.b4a.phone.PhoneEvents$16.onReceive(PhoneEvents.java:268)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:905)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:198)
at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:137)
at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:440)
at b4a.G8.STLSK.main._pe_smssentstatus(main.java:2671)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.phone.PhoneEvents$ActionHandler.send(PhoneEvents.java:326)
at anywheresoftware.b4a.phone.PhoneEvents$10.handle(PhoneEvents.java:188)
at anywheresoftware.b4a.phone.PhoneEvents$16.onReceive(PhoneEvents.java:268)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:905)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5643)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.iutputStream
code
B4X:
Try
printer.Initialize2(btserial2.OutputStream,"CP1256")
printer.WriteLine(Chr(28) & "p" & Chr(1) & "1")
printer.WriteLine(getreceiptdate)
printer.WriteLine(getreceipttime)
printer.WriteLine("")
printer.WriteLine("")
printer.Flush
ToastMessageShow("Printed",False)
printer.Close
btserial2.Disconnect
Catch
Log(LastException)
btserial2.Disconnect
End Try
Sub getreceipttime As String
Dim hour As String
Dim Minutes As String
Dim Seconds As String
Dim Meridian As String
Dim TheTime As String
hour = DateTime.GetHour(DateTime.Now)
Minutes = DateTime.GetMinute(DateTime.Now)
Seconds = DateTime.GetSecond(DateTime.Now)
If hour < 12 Then Meridian = " AM"
If hour = 12 Then Meridian = " PM"
If hour = 0 Then
hour = 12
Meridian = " AM"
End If
If hour > 12 Then
hour = hour - 12
Meridian = " PM"
End If
TheTime = NumberFormat(hour, 2, 0) & ":" & NumberFormat(Minutes, 2, 0) & ":" & NumberFormat(Seconds, 2, 0) & Meridian
Return TheTime
End Sub
Sub getreceiptdate As String
Dim month As String
Dim day As String
Dim year As String
Dim getmonth As String
Dim date As String
month = DateTime.GetMonth(DateTime.Now)
day = DateTime.GetDayOfMonth(DateTime.Now)
year = DateTime.GetYear(DateTime.Now)
Select month
Case "1"
getmonth = "January"
Case "2"
getmonth = "February"
Case "3"
getmonth = "March"
Case "4"
getmonth = "April"
Case "5"
getmonth = "May"
Case "6"
getmonth = "June"
Case "7"
getmonth = "July"
Case "8"
getmonth = "August"
Case "9"
getmonth = "September"
Case "10"
getmonth = "October"
Case "11"
getmonth = "November"
Case "12"
getmonth = "December"
End Select
date = getmonth&" - "&day& " - "&year
Return date
End Sub
Last edited: