Java Question Inline Java how can i return a simple B4A MAP

Discussion in 'Libraries developers questions' started by Siam, Aug 10, 2015.

  1. Siam

    Siam Active Member Licensed User


    im playing with the Inline Java and i will return a Simple Map (not Treemap or haschmap or is there a trick to convert this to b4a map?)

    my Problem beginns with:

    import java.util.Map;

    public Certificate chkssl(String Server)
      throws IOException, CertificateException, CertificateEncodingException
    Map mape = new Map(); <- will give the error
    error :

    error: Map is abstract; cannot be instantiated
    Map mape = new Map();

    if i use :
    Map mape = new hashMap();
    Map mape = new treeMap();

    it works but B4A don't understand the hashmap or the tree map is there a other Lib needed ?


  2. Erel

    Erel Administrator Staff Member Licensed User

    import anywheresoftware.b4a.objects.collections.Map;

    Map m = new Map();

    return m.getObject();
    Mashiane likes this.
  3. LucaMs

    LucaMs Expert Licensed User

    Ehm... I was studying...

    This code... does not work :D

    #If JAVA
    import java.util.*;
    public Map<Object, Object> MapTest() {
        Map<Object, Object> mymap = new HashMap<Object, Object>();
        return mymap;
    #End IF
  4. Siam

    Siam Active Member Licensed User

    thx i will test it!
    Last edited: Aug 11, 2015
  5. Siam

    Siam Active Member Licensed User

    :oops:the next problem :oops:

    if i do

    public Map chkssl(String Server)
    Map ma = new Map();
    return m.getObject();

    i get this errors:

    required: Map
    found: MyMap

    if i change to

    public MyMap chkssl(String Server)

    i get this error

    error: cannot find symbol
    public MyMap chkssl(String Server)


    if i do

    return ma;

    This error :

    java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap

    on this line:

    Dim s As Map
    s = NativeMe.RunMethod("chkssl",Array(""))


    some hints are wellcome

  6. Siam

    Siam Active Member Licensed User


    problem Solved :D

    this is wrong:

    public Map chkssl(String Server)

    this solves my Problem:

    public Object chkssl(String Server)

    thx thx thx !!!!

    and now i have the next question's:

    is it possible to use Inline Java when i use the B4A compile to Library Option?
    if yes how it works? if i Call

    s= NativeMe.RunMethod("chkssl1",Array(url))

    i get the error

    java.lang.RuntimeException: Method: chkssl1 not found in: b4a.example.main

    and the next is there something like this: vor the B4a core Libs ?


    Mashiane likes this.
  7. Roycefer

    Roycefer Well-Known Member Licensed User

    Where are you putting the chkssl1 inline Java method? The Main module isn't compiled when you compile to a library. That means you'll have to put the chkssl1 inline Java method somewhere else and that you can only call it from that same module/class.
  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