Android Code Snippet [B4X] Tip: logging arrays of numeric values

Code: Copy
Dim d() As Double = Array As Double(1, 2.3, 4.5)
Log(d)

The result of this code is a compilation error:

src\b4j\example\main.java:44: error: no suitable method found for NumberToString(double[])
anywheresoftware.b4a.keywords.Common.LogImpl("265538",BA.NumberToString(_d),0);
^
method BA.NumberToString(double) is not applicable
(argument mismatch; double[] cannot be converted to double)...


The solution is to cast the array to a List:
Code: Copy
Log(d.As(List))

Output:
(ArrayList) [1.0, 2.3, 4.5]


And for bytes I usually use agraham's useful ByteConverter library (internal library in B4A and B4J, and integrated in iRandomAccessFile library in B4i):
Code: Copy
Dim bc As ByteConverter
Dim b() As Byte = Array As Byte(1, 2, 3, 4, 5, 0xab)
Log(bc.HexFromBytes(b))

0102030405AB
 
Last edited:
Back
Top