Android Question Error "Attempt to write to field" (randomaccessfile.AsyncStreams)

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I am encountering a problem that is far beyond my knowledge.

I am using the Bluetooth ESC/POS Printer Class
To print to a battery powered portable printer.

Everything works apparently fine, but if the printer is turned off, which can happen because it has an automatic timeout to save battery, or because the user decides to turn it off, then an error occurs and my program closes.

I have tried to find a solution by inserting "try cath..." in all the places where the "stream" (Private Stream As AsyncStreams) is used, but I have not been able to control the problem.
The message displayed by the log is:
B4X:
"java.lang.NullPointerException: Attempt to write to field 'java.lang.Exception anywheresoftware.b4a.BA$SharedProcessBA.lastException' on a null object reference in method 'void anywheresoftware.b4a.BA.setLastException(java.lang.Exception)'
    at anywheresoftware.b4a.BA.setLastException(BA.java:663)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:292) at java.lang.Thread.run(Thread.java:1012)"

So, what I need, at least, is to be able to control this error so that the program keeps working and does not close.
So I can keep retrying to connect to the printer until they reconnect it.

I wish you guys can help me, because I am totally lost with this topic.
Thank you very much.
 

vecino

Well-Known Member
Licensed User
Longtime User
I want to clarify that the problem occurs as soon as the printer is turned off, the program does not need to be printing.
The program is doing nothing waiting for the user to initiate a sale, so if the printer is turned off, this error occurs.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…