Java Question Impossible to pass List as parameter in event?

alwaysbusy

Expert
Licensed User
Longtime User
[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:
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.
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:
B4X:
ba.raiseEvent(this,eventName + "_receivedgetqueue" , status, statusmessage, Integer.parseInt(numberOfMessages), new Object[]{ids});
but no luck either.

Any insight or pointer is greatly appriciated.

Alain
 
Last edited:

alwaysbusy

Expert
Licensed User
Longtime User
Hi Erel,

I've tried your suggestion:
B4X:
ba.raiseEvent(this,eventName + "_receivedgetqueue" , status, statusmessage, Integer.parseInt(numberOfMessages), AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), ids));

But then I also get the error 'java.lang.NegativeArraySizeException: -1' although the size is bigger than 0. This is the same error as if I declared ids as
anywheresoftware.b4a.objects.collections.List in the first place:

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.getSize());
            }
            
            ba.raiseEvent(this,eventName + "_receivedgetqueue" , status, statusmessage, Integer.parseInt(numberOfMessages), ids);

The code is property of my client so i can't post the full code but I'll try to setup a mini lib that could reproduce this error.

Alain
 

alwaysbusy

Expert
Licensed User
Longtime User
Hi Erel,

Your solution worked Erel. The second error (java.lang.NegativeArraySizeException: -1) was actually correct. As I'm programming in 4 languages at the same time for the moment I overlooked:

B4X:
Dim tmpSplit(-1) As String

which is valid in RealBasic, but obviously not in b4A and Java

Thanks for the help Erel. It seems the all nighter is getting a grip on me and I better get some sleep.

Cheers,

Alain
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…