XverhelstX Well-Known Member Licensed User Longtime User Jul 14, 2013 #1 Hi I need some help porting the following code from Java to Basic4Android Code: Copy 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) Code: Copy 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: Jul 14, 2013
Hi I need some help porting the following code from Java to Basic4Android Code: Copy 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) Code: Copy 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
mc73 Well-Known Member Licensed User Longtime User Jul 14, 2013 #2 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: Jul 14, 2013 Upvote 0
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.
agraham Expert Licensed User Longtime User Jul 15, 2013 #3 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
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.