Hi all!
I have a question:
This thread https://www.b4x.com/android/forum/threads/how-to-convert-list-to-byte-array.67303/ explains on how to convert a normal list into a byte array.
@Erel provided this simple method for that:
But, what happens if each entry in the list object has more than 1 byte.
Example:
My list contains 4 entries.
Each entry has such a content: "Hello World".
The list.size is 4 and the target byte array has only a size of 4 bytes.
This makes sense, because - while using this method - I get always this error:
And line 613 is this one:
Is there something missing?
Or should I cast something to another type?
Perhaps somebody can help here.
Additional information:
My list object contains data from Audiostreamer (see example for recording audio data). In this example a normal list is used as "audiobuffer".
Regards and thanks in advance
ARTsoft
I have a question:
This thread https://www.b4x.com/android/forum/threads/how-to-convert-list-to-byte-array.67303/ explains on how to convert a normal list into a byte array.
@Erel provided this simple method for that:
B4X:
Sub ListToBytes(list As List) As Byte()
Dim b(list.Size) As Byte
For i = 0 To list.Size - 1
b(i) = list.Get(i)
Next
Return b
End Sub
But, what happens if each entry in the list object has more than 1 byte.
Example:
My list contains 4 entries.
Each entry has such a content: "Hello World".
The list.size is 4 and the target byte array has only a size of 4 bytes.
This makes sense, because - while using this method - I get always this error:
B4X:
Error occurred on line: 613 (Tools)
java.lang.NumberFormatException: For input string: "[B@15041a8"
at jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
at jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:543)
at anywheresoftware.b4a.debug.RDebugUtils.numberCast(RDebugUtils.java:63)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:265)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8168)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)
And line 613 is this one:
B4X:
b(i) = list.Get(i)
Is there something missing?
Or should I cast something to another type?
Perhaps somebody can help here.
Additional information:
My list object contains data from Audiostreamer (see example for recording audio data). In this example a normal list is used as "audiobuffer".
Regards and thanks in advance
ARTsoft
Last edited: