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

Discussion in 'Android Questions' started by analizer3816, Aug 17, 2018.

  1. analizer3816

    analizer3816 Member Licensed 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

    this is my test lib
    java library code:
    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;

    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() {
        public Map testmap() {
            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() {   
            m1.Put("m11", "m11");
            m1.Put("m12", "m12");
            return l;
    b4a code:
    Dim tl As testlib
    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
  2. analizer3816

    analizer3816 Member Licensed User

    ok, I fixed it

    use list.getObject(); and map.getObject();
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice