Hi,
the javacode below (defined in a library using "hashmap to map convert example" from another related thread) causes in B4J a java.lang.ClassCastException when assigning a list map entry to a B4J map.
Checking content via createmap, the result is the same content as in the list map entries created via the library.
Any hints on the cause for this exception?
//B4J Code
// JAVA CODE
the javacode below (defined in a library using "hashmap to map convert example" from another related thread) causes in B4J a java.lang.ClassCastException when assigning a list map entry to a B4J map.
Checking content via createmap, the result is the same content as in the list map entries created via the library.
Any hints on the cause for this exception?
//B4J Code
B4X:
Dim l As List = cl.ColorMap
Log(l.Get(0))
'OUTPUT = (MyMap) {Name=TRANSPARENT, Value=0x00000000}
For i = 0 To 1
Log(l.Get(i))
Dim m As Map = l.Get(i)
' EXCEPTION:
' java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
Next
// JAVA CODE
B4X:
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import javafx.scene.paint.Color;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.objects.collections.Map;
..
.. additional code
..
//List of Color Names and Values as a Map
public static List<Map> getColorMap() throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException
{
List<Map> colors = new ArrayList<Map>();
Class<?> clcolor = Class.forName("javafx.scene.paint.Color");
if (clcolor != null) {
Field[] field = clcolor.getFields();
for (int i = 0; i < field.length; i++) {
Field f = field[i];
// Get Name
Object objn = f.get(null);
if(objn instanceof Color){
Color c = (Color) objn;
Map m = new Map();
m.Initialize();
m.Put("Name", f.getName());
m.Put("Value", c.toString());
colors.add(m);
}
}
}
return colors;
}