Double byte array

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hi

I need some help porting the following code from Java to Basic4Android

B4X:
public boolean sendData(String toChannel, byte[] buf) {
   byte[][] payload = new byte[1][];
   payload[0] = buf;
   return true;

}

In Basic4Android, this seems to give me a nullpointer: (the npe occurs when sending the actual data)
B4X:
Public Sub SendData(NodeName As String, Prefix As String, Buffer() As Byte) As Boolean

Dim Payload(1,1) As Byte
   Payload(0,0) = Buffer(0)
return true

What is the correct equivalent for this double array?

Regards,
Tomas
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
You get a correct log of byte(0)?
Oh, and from what I see, you should loop and set payload(0,n)=buffer(n). But I don't see why this would npe.
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
Byte[][] is a jagged array, or an array of arrays which are the only type of multi-dimensional array supported by Java. Normally they look and behave like normal arrays but occasionally, like here, there are slight differences. Here payload is effectively declared an array[1] to which is being assigned another array, buf[] whose elements will now be accessed as payload[0][x].

I guess you have missed out some code from the sendData function because as it stands it is nonsensical because payload is a local variable but its multi-dimensionality is not being used. You will need to see from the code how the multi-dimensionality is being used and translate that to B4A.
 
Upvote 0
Top