Hi, I've a problem with 2 byte array.
I've first byte array named ActCode that have length of 800 bytes:
I pass this array in a Sub as argument, and I need to attach this to another array.
The function called is:
But I've always this error:
I tried too to substitute bc.ArrayCopy to:
and tried to make ActCode smaller then 800 bytes (2 bytes) but without any improvement.
I checked more times, and:
PLoad contains correct data.
Pkt is defined with correct size and sure defined as Byte array.
ActCode is defined as Byte array.
I'm sure I'm doing something wrong, but I don't understand what.
Can you help me?
Thanks.
I've first byte array named ActCode that have length of 800 bytes:
B4X:
Public const ActCode() As Byte = Array(0xc9, 0x44 ... )
I pass this array in a Sub as argument, and I need to attach this to another array.
B4X:
SendData(0x06, ActCode)
The function called is:
B4X:
Sub SendData(Type As Byte, PLoad() As Byte)
Dim size as Int = ... Calculated about Type parameter
Dim Pkt(Size) As Byte
Pkt(0) = HEADER
Pkt(1) = Type
If PLoad <> Null Then bc.ArrayCopy(PLoad, 0, Pkt, 2, PLoad.Length)
...
EndSub
But I've always this error:
Error occurred on line: 336
java.lang.IllegalArgumentException: Array has incompatible type: class [B
at java.lang.reflect.Array.incompatibleType(Array.java:776)
at java.lang.reflect.Array.badArray(Array.java:785)
at java.lang.reflect.Array.setInt(Array.java:637)
at java.lang.reflect.Array.set(Array.java:468)
at anywheresoftware.b4a.shell.ArraysUtils.setElement(ArraysUtils.java:84)
at anywheresoftware.b4a.shell.Shell.setArrayElement(Shell.java:591)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:386)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6291)
at android.view.View$PerformClick.run(View.java:24931)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
I tried too to substitute bc.ArrayCopy to:
B4X:
If PLoad <> Null Then
For I = 0 To PLoad.Length-1
Pkt(2+I) = PLoad(I)
Next
End If
and tried to make ActCode smaller then 800 bytes (2 bytes) but without any improvement.
I checked more times, and:
PLoad contains correct data.
Pkt is defined with correct size and sure defined as Byte array.
ActCode is defined as Byte array.
I'm sure I'm doing something wrong, but I don't understand what.
Can you help me?
Thanks.
Last edited: