Java Question Library & where to Initialise in B4A

tchart

Well-Known Member
Licensed User
Longtime User
One of my libraries wraps a DatagramSocket for sending UDP commands. I'm using the library in a project that uses a service. The library object is declared in the "Sub Process_Globals" for the service.

I've found that if I initialise in "Sub Service_Create As Boolean" then everything is OK.

However if I initialise elsewhere in the service code the socket is not initialised the first time I call the DatagramSocket's Send function ie the first Send fails but the second succeeds. The first send also throws an Java error but the app doesn't crash.

Has anybody seen this before? Ideally I would like to solve the issue as I would like to initialise the object when I need it rather than when the service is created.

Could the problem be the definition of the class? public class BridgeWrapper implements BA.CheckForReinitialize

Or the fact that I've declared it as a global?
 

tchart

Well-Known Member
Licensed User
Longtime User
Erel, sorry took me a while to get back to this. Here is the error.

SendFinal IOException
java.lang.NullPointerException
at com.tchart.limitlessled.BridgeWrapper$1.run(BridgeWrapper.java:119)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)

The odd thing is that this error is not thrown on my Note 3 (4.4.2) but is thrown on my HUAWEI Vodafone 858 (2.2.2). It must be something to do with the version of Android. I'll test on some other devices.

Thanks
 
Top