[SOLVED]Impossible to pass List as parameter in event?
Hi,
I'm struggling for a couple of hours now on a thing that should be so obvious so I direct my problem to the forum.
In a library, I want to raise an event that has one List parameter.
Declaration:
Relevant calling Java:
Event in B4A
The log:
Note: Error line 1807 is the 'ba.raiseEvent' line
This error occurs when I use 'ids' as a List. (I've tried defining it as an array but then I get the error 'java.lang.NegativeArraySizeException: -1' although the size is bigger than 0).
If I replace ids by a comma delimited string the event is raised correctly, so the problem must be with defining ids as list or array.
I've tried raising the event like this:
but no luck either.
Any insight or pointer is greatly appriciated.
Alain
Hi,
I'm struggling for a couple of hours now on a thing that should be so obvious so I direct my problem to the forum.
In a library, I want to raise an event that has one List parameter.
Declaration:
B4X:
@ShortName("ABXMLRPC")
@Version(1.0f)
@Author("Alain Bailleul")
@Events(values={"ReceivedGetQueue(status as Int, statusMessage as String, numberOfMessages as Int, idList as List)"})
@Permissions(values={"android.permission.INTERNET"})
public class ABXMLRPC {
Relevant calling Java:
B4X:
status=GetResponseInt(1001,"status");
statusmessage=GetResponseString(1001,"statusmessage");
String idstr="";
//anywheresoftware.b4a.objects.collections.List ids=new anywheresoftware.b4a.objects.collections.List();
//ids.Initialize();
List<String> ids = new ArrayList<String>();
String tmpIds[] = new String[0];
String numberOfMessages="0";
if (status<0) {
numberOfMessages=GetResponseString(1001,"numberofmessages");
idstr=GetResponseString(1001,"ids");
tmpIds = idstr.split(";");
for (int i=0;i<tmpIds.length;i++) {
ids.add(tmpIds[i]);
}
}
if (DoDebug) {
Log.d("INFO: ", "numberOfMessages="+numberOfMessages);
Log.d("INFO: ", "idssize="+ids.size());
}
ba.raiseEvent(this,eventName + "_receivedgetqueue" , status, statusmessage, Integer.parseInt(numberOfMessages), ids);
Event in B4A
B4X:
Sub myrpc_ReceivedGetQueue(status As Int, statusMessage As String, numberOfMessages As Int, idList As List)
If status = -1 Then
Dim a As Int
Dim idsinfo As String
Dim idstr As String
Queue.Initialize
For a = 0 To numberOfMessages-1
idsinfo = idsinfo & idList.get(a) & Chr(10)
Dim tmpSplit(-1) As String
tmpSplit = Regex.Split(",",idList.get(a))
If tmpSplit.Length > -1 Then
idstr = idstr & tmpSplit(0) & " "
Queue.Put(tmpSplit(0),idList.get(a))
End If
Next
txtLog.Text = "Get Queue (OK=-1): " & status & " " & statusMessage & Chr(10) & numberOfMessages & Chr(10) & idsinfo & txtLog.Text
lblQueue.Text = idstr
Else
txtLog.Text = "Get Queue (OK=-1): " & status & " " & statusMessage & Chr(10) & txtLog.Text
lblQueue.Text = ""
End If
End Sub
The log:
B4X:
numberOfMessages=1
idssize=1
main_cmdgetqueue_click (java line: 462)
java.lang.Exception: Sub myrpc_receivedgetqueue signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:172)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
at com.AB.ABXMLRPC.ABXMLRPC.BASECallServer(ABXMLRPC.java:1807)
at com.AB.ABXMLRPC.ABXMLRPC.ABQuery(ABXMLRPC.java:924)
at com.AB.ABXMLRPC.ABXMLRPC.HF_GetQueue(ABXMLRPC.java:542)
at com.ab.xmlrpctest.main._cmdgetqueue_click(main.java:462)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:158)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:54)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14110)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
java.lang.Exception: Sub myrpc_receivedgetqueue signature does not match expected signature.
This error occurs when I use 'ids' as a List. (I've tried defining it as an array but then I get the error 'java.lang.NegativeArraySizeException: -1' although the size is bigger than 0).
If I replace ids by a comma delimited string the event is raised correctly, so the problem must be with defining ids as list or array.
I've tried raising the event like this:
B4X:
ba.raiseEvent(this,eventName + "_receivedgetqueue" , status, statusmessage, Integer.parseInt(numberOfMessages), new Object[]{ids});
Any insight or pointer is greatly appriciated.
Alain
Last edited: