Android Question Debug problem java.lang.RuntimeException: Unable to create service

davemorris

Active Member
Licensed User
Hi Guys

I have a problem with some code - as soon as it attempts to run in debug I get the following Error report (it is OK if compiled as a release version). Previously this code as worked when last tested about a month ago.

Error log:
java.lang.RuntimeException: Unable to create service arena.Epos.starter: java.lang.RuntimeException: java.net.SocketException: sendto failed: EBADF (Bad file descriptor)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3096)
    at android.app.ActivityThread.-wrap4(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1586)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:5816)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: java.lang.RuntimeException: java.net.SocketException: sendto failed: EBADF (Bad file descriptor)
    at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:164)
    at anywheresoftware.b4a.shell.Shell.start(Shell.java:102)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:92)
    at arena.Epos.starter.onCreate(starter.java:34)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3086)
    ... 8 more
Caused by: java.net.SocketException: sendto failed: EBADF (Bad file descriptor)
    at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:577)
    at libcore.io.IoBridge.sendto(IoBridge.java:546)
    at java.net.PlainSocketImpl.write(PlainSocketImpl.java:509)
    at java.net.PlainSocketImpl.-wrap1(PlainSocketImpl.java)
    at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:271)
    at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85)
    at anywheresoftware.b4a.shell.ShellConnector.sendControlMessage(ShellConnector.java:62)
    at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:124)
    ... 12 more
Caused by: android.system.ErrnoException: sendto failed: EBADF (Bad file descriptor)
    at libcore.io.Posix.sendtoBytes(Native Method)
    at libcore.io.Posix.sendto(Posix.java:211)
    at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:278)
    at libcore.io.IoBridge.sendto(IoBridge.java:544)
    ... 19 more

I have had this type of error before but usually if is fixed after invoking Tools->Clean Project - but this error occurs every time I attempt run it in debug.

I am using v10.0 of B4A - the phone is an Android 6 and I am using a USB connection to the device.
I have tried the following
Unstall the original App on the phone.
Reset the phone
Restarted the IDE and rebooted the computer.

Can anyone give me a pointer?

Kind regards
Dave Morris
 

davemorris

Active Member
Licensed User
Hi Erel
Does it only happen with this specific app?
Only appears to happen with this App (another App I tried is OK).

Make sure that there is no invalid code in one of the Process_Globals subs.
I will look through the code an see if I can find something.
Its a large project, can you give me any guidelines how to find out what is causing the problem - there is nothing in the logs (would the unfiltered log give me more information?).

Regards
Dave Morris
 
Upvote 0

davemorris

Active Member
Licensed User
Hi Erel
Make sure that there is no invalid code in one of the Process_Globals subs.
Looking through the code
The 15 Activity Process_Globals do not contain any code.
The 6 Service Process_Global only contain a mixture of Public and Private Constants, variables and one also contains a Type.

There are also 65 classes but don't have a Process_Global.

Regards
Dave
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
The 15 Activity Process_Globals do not contain any code.
As I just found it with a similar problem it doesn't need to be actual code that's the problem. Invalidly accessing an object can alo cause the problem. It's a SocketException so look for network objects or methods.
 
Upvote 0

davemorris

Active Member
Licensed User
Hi agraham
It's a SocketException so look for network objects or methods
I removed all code relating to the network objects - references to objects AsyncStreams and Socket using a compiler switch.
Then tried to compile and it worked - great. So I tried to reintroduce the code in stages to try to find out what was causing the damage. I ended up by introducing all the code I removed and it still ran in debug!

Then compiled again (after invoking Tools->Clean Project) and it failed - repeated and it run in debug.

Basically I am back to where I started - sometimes the code runs- sometimes it starts and throws the exception.

It has, as often happens, improved during the day (sometimes without changing the code).

There is something wrong somewhere but until it happens every time I can't isolate it!

Its a high probability it's my code but it does run in a release version without problems.

Kind regards
Dave Morris
 
Upvote 0

davemorris

Active Member
Licensed User
Hi agraham
That smacks of a timing issue
I would totally agree - it's a shame I can't get any more information (which I can understand) from the logs giving an indication where the problem is. I think it would be a useful exercise - and the results would be good for the Forum.

Regards
Dave Morris
 
Upvote 0

davemorris

Active Member
Licensed User
Hi Erel
Thanks for offering to help - As it is a commercial App I will need to send it outside the forum - how is the best way to send it? (Obviously I have no objection to making the results public if it would be useful to other users).

Kind regards
Dave Morris
 
Upvote 0

davemorris

Active Member
Licensed User
Hi Erel (I know this is an old thread but it may help someone with similar problems)

Thanks for the offer to have a look at my software - but since you offered, the problem has gone away or is OK after a few repeated attempts to run it.

However, today it did kick up and would not run in debug mode no matter what I did.

However, I found a fix by switching from the USB connection (my normal method of Debug) to the B4A-bridge and it worked! Switched back to USB and the problem returned but appears OK when switched back to the B4A bridge.

I could still send my code if it helps - but I would feel guilty asking Erel to have a look only to find that I have done something horrible in the code (and should have read the manual!).

If Erel still wants the code then I will happily send it - or if the problem is USB related, then I am happy for some suggestions to crack the problem.

Kind regards
Dave
 
Upvote 0
Top