Android Question cannot get data in List & Map from java library

analizer3816

Member
Licensed User
Longtime User
I can't get size or data in list and map from java lib
[I need java lib + b4a and use list in map , map in map, map in list or list in list]

please suggest me for fixed this problem
thanks

this is my test lib
java library code:
B4X:
ackage testlib;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.collections.List;
import anywheresoftware.b4a.objects.collections.Map;

@ShortName("testlib")
@Version(1.0f)
public class testlib {
    private List l1 = new List();
    private List l2 = new List();
    private Map m = new Map();
    private Map m1 = new Map();
    private List l = new List();
    
    public void initialize() {
        l1.Initialize();
        l2.Initialize();
        m.Initialize();
        m1.Initialize();
        l.Initialize();
    }
    
    public Map testmap() {
        l1.Add("l11");
        l1.Add("l12");
        l2.Add("l21");
        l2.Add("l22");
        
        m1.Put("m11", "m11");
        m1.Put("m12", "m12");
        
        m.Put("l1", l1);
        m.Put("l2", l2);
        m.Put("m1", m1);
        
        return m;
    }
    
    public List testlist() {   
        l1.Add("l11");
        l1.Add("l12");
        l2.Add("l21");
        l2.Add("l22");
        
        m1.Put("m11", "m11");
        m1.Put("m12", "m12");
        
        l.Add(l1);
        l.Add(l2);
        l.Add(m1);
        
        return l;
    }
}

b4a code:
B4X:
    Dim tl As testlib
    tl.initialize()
    Dim m As Map = tl.testmap
    Dim m1 As Map = m.Get("m1")
    Log(GetType(m.Get("m1")))    '>> anywheresoftware.b4a.objects.collections.Map
    Log(m1)    '>> (Map)(MyMap){m11=m11, m12=m12}
    Log(m1.size)    '>> java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap

    Dim l As List = tl.testlist
    Dim l1 As List = l.Get(0)
    Log(GetType(l.Get(0)))    '>> anywheresoftware.b4a.objects.collections.List
    Log(l)    '>> (ArrayList) [(ArrayList) [l11, l12, l11, l12], (ArrayList) [l21, l22, l21, l22], (MyMap) {m11=m11, m12=m12}]
    Log(l1.size)    '>> java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.List cannot be cast to java.util.List
 
Top