Hi
I add one new parameter to "connecto". I always get a message as following when i running "callsub3". Why ....?
Main Activity
starter service
I add one new parameter to "connecto". I always get a message as following when i running "callsub3". Why ....?
B4X:
Error loading state.
java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3
** Activity (main) Resume **
Error occurred on line: 47 (Main)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.keywords.Common.CallSubDebug3(Common.java:862)
at b4a.ioapp.main._btnconnect_click(main.java:453)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:336)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4261)
at android.view.View$PerformClick.run(View.java:17356)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
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:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.Exception: Sub ConnectTo signature does not match expected signature.
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336)
at anywheresoftware.b4a.debug.Debug.CallSubNew3(Debug.java:288)
... 26 more
Caused by: java.lang.Exception: Sub ConnectTo signature does not match expected signature.
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:321)
... 27 more
** Activity (main) Resume **
B4X:
Sub btnConnect_Click
Dim host As String = "104.168.146.153"
If (txtAccount.Text="")Or(txtPassword.text="") Then
ToastMessageShow("帳號,密碼輸入有誤!", True)
Return
End If
Dim acc As String=txtAccount.Text
Dim pwd As String=txtPassword.Text
CallSub3(Starter, "ConnectTo",acc,pwd) <<<--- call this have exception
End Sub
B4X:
Public Sub ConnectTo(Host As String, account As String,password As String) <<<--- Main will call this !
currentName = "io-app"
Hostname = Host
HostAcc = account
HostPwd = password
If connected Then client.Close
client.Initialize("client", $"tcp://${Hostname}:${port}"$, "android" & Rnd(1, 10000000))
Dim mo As MqttConnectOptions
mo.Initialize(HostAcc,HostPwd)
'this message will be sent if the client is disconnected unexpectedly.
mo.SetLastWill("all/disconnect", serializator.ConvertObjectToBytes(currentName), 0, False)
client.Connect2(mo)
End Sub