Android Question JavaObject-Passing arrays as a parameters

JTmartins

Active Member
Licensed User
Longtime User
Hi, I'v faced this situation, where I have to pass some parameters to an external jar but some are arrays and others are not.

The java code is :
B4X:
public int transmit(int slotNum,
           byte[] sendBuffer,
           int sendBufferLength,
           byte[] recvBuffer,
           int recvBufferLength)

Now in my B4A I have

B4X:
Private SendBuffer(6) As Byte
SendBuffer(0)=0x00
SendBuffer(1)=0xA4
SendBuffer(2)=0x08
SendBuffer(3)=0x0C
SendBuffer(4)=0x02
SendBuffer(5)=0x2F
Private recvBuffer(300) As Byte

and the JavaObject Line would be something similar as the one below, wich obviously does not work.


B4X:
Dim response As JavaObject
response=mReader.RunMethod("transmit", Array As JavaObject (slotnum, Array As Byte (SendBuffer()) ,SendBuffer.Length, Array As Byte (recvBuffer()), recvBuffer.Length ))

I've looked java.initialize array, but I could not figure how to use it in this situation.

every different attempts I've tryed always lead me to

java.lang.IllegalArgumentException: Array has incompatible type:

I'me prety sure there is a solution, as always,
Help !
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
Have you tried (as the compiler should know which items are arrays)
B4X:
response=mReader.RunMethod("transmit", Array(slotnum, SendBuffer ,SendBuffer.Length, recvBuffer, recvBuffer.Length ))
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
That was my first attempt wich gave me

java.lang.reflect.InvocationTargetException
Caused by: java.lang.IllegalArgumentException


I have to look deeper into this, as this may indicate an error in the parameters I'm sending, but in the mean time if some one can throw some ideas, I would appreciate.

Many thanks Daestrum
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
Yeap. You where right Daestrum...It was my mistake. Sending incorrectly formed arrays.

I still haven't decyphered the responses, but I'm getting them now.
 
Upvote 0
Top