Android Question Threading lib trouble under B4A 6.3

peacemaker

Expert
Licensed User
Longtime User
Seems, the lib sample is not working in B4A 6.3... :-(
C:\Program Files\Java\jdk1.8.0_77\bin\javac.exe - Java 8 Update 91 - is it important ?

A new thread is started, but ended with the error:
error=Exception : wrong number of arguments; expected 4, got 0

Errors, if
B4X:
Dim args(4) As Object
error=Exception : argument 1 should have type java.lang.String, got java.lang.Object
error=Exception : argument 2 should have type java.lang.String, got java.lang.Object
error=Exception : argument 3 should have type java.lang.Object[], got java.lang.Object

This:
B4X:
Dim args(4) As Object
args(0) = ""
args(1) = ""
Dim args2(0) As Object
args(2) = args2
Log(thread1.Start(Me, "Th_read", args))
gives in

B4X:
Sub Thread1_Ended(fail As Boolean, error As String) 'An error or Exception has occurred in the Thread
Log("fail=" & fail)   ' gives FALSE !!!
Log("error=" & error)   ', but next ERROR:
End Sub

B4X:
** Service (starter) Create **
** Service (starter) Start **
Unexpected event (missing RaiseSynchronousEvents):
Check the unfiltered logs for the full stack trace.
java.lang.RuntimeException: java.io.EOFException
    at anywheresoftware.b4a.shell.Shell$2.run(Shell.java:313)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.EOFException
    at java.io.DataInputStream.readByte(DataInputStream.java:98)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:333)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at anywheresoftware.b4a.shell.Shell$2.run(Shell.java:311)
    ... 9 more

Heeeelp !
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
If in release mode - sometimes the error returned from the new thread:
error=Exception : Can't create handler inside thread that has not called Looper.prepare()

UPD: now this error is always (((
If to start the sub as usual in the main thread - no problem, but slow, it needs background running
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Actually, this long loop sub is OK now, if to remove all DOEVENTS. But anyway, it would be good to understand the rules how to use subs structure in another thread.
If it's another sub that uses another subs, with parameters... and how to get the result back correctly...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…