Hi,
I am trying to send some text from a sub in a service to a label in the activity.
I always get an error
Service
B4X:
Sub WinRESTSocket_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
IncomingStream.Initialize(NewSocket.InputStream, NewSocket.OutputStream, "IncomingStream")
CallSubDelayed2(Main,"ShowLog","Connected to WinREST")
End If
WinRESTSocket.Listen
End Sub
Activity
B4X:
Sub ShowLog(Text2show As String, clear As Boolean)
If clear = True Then
lblStatus.text=""
Else
lblStatus.text = lblStatus.text & Text2show & CRLF
End If
End Sub
Error
B4X:
-------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (CallSubDelayed - ShowLog)
running waiting messages (1)
An error occurred:
(Line: 61) End Sub
java.lang.Exception: Sub showlog signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject p2g.Wrst2Zarph.main_subs_0._showlog(anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject) throws java.lang.Exception
class anywheresoftware.b4a.pc.RemoteObject,
You're expecting two parameters, a string and a Boolean and you're only passing a string. Also, you should probably change the name of the sub to "Show_Log" if you plan to obfuscate the project at some point.
This is the signature from callsubdelayed2
CallSubDelayed2 (Component As Object, Sub As String, Argument As Object)
The last parameter is an OBJECT. You only can give ONE parameter.
You are giving a String here....
B4X:
CallSubDelayed2(Main,"ShowLog","Connected to WinREST")
But your sub needs two parameters... So i suggest to use a List or a Map as Parameter and get the right values out of the List/Map.
Additionally you should have an underscore in the subname if you plan to compile obfuscated.
B4X:
dim m as map = CreateMap("Text2Show":"MyText","Clear":true)
CallSubDelayed2(Main,"Show_Log",m)
B4X:
Sub Show_Log(cfg as Map)
dim text2show as string = cfg.get("Text2Show")
dim clear as boolean = cfg.get("Clear")
If clear = True Then
lblStatus.text=""
Else
lblStatus.text = lblStatus.text & Text2show & CRLF
End If
End Sub
you also can use CallSubDelayed3 and pass two parameters.
But if you need more parameters then you need to use a Map or a List. So i suggest to use a Map directly. You can put everything into the Map.
My answer was NOT meant to YOU! I´m NOT INTERESTED in anything you write (say it layoutproblems, nullpointer exceptions or whatever). You are on my ignorelist. So basically i do not see such posts. But sometime i reveal the post...
Don´t expect any answer from me (expect this one) to be a answer to your post!