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

    Hello,

    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:

    Code:
    import java.util.Map;

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

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

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

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

    greetings

    Andy
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    import anywheresoftware.b4a.objects.collections.Map;

    Map m = new Map();
    m.Initialize();

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

    LucaMs Expert Licensed User

    Ehm... I was studying...

    This code... does not work :D

    Code:
    #If JAVA
    import java.util.*;
    public Map<Object, Object> MapTest() {
        Map<Object, Object> mymap = new HashMap<Object, Object>();
        mymap.put("x","Luca");
        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();
    ma.Initialize();
    ma.Put("test","1111");
    ma.Put("test2","22222");
    .
    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)

    :confused:

    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.Initialize
    s = NativeMe.RunMethod("chkssl",Array("https://kleinersonnenschein.eu"))

    :oops::(

    some hints are wellcome

    andy
     
  6. Siam

    Siam Active Member Licensed User

    Hi,

    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: http://developer.android.com/reference/java/security/cert/Certificate.html# vor the B4a core Libs ?

    greets

    Andy
     
    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.
     
Loading...
  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