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

Siam

Active Member
Licensed User
Longtime 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:

B4X:
import java.util.Map;

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

error :

B4X:
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
 

LucaMs

Expert
Licensed User
Longtime User
Ehm... I was studying...

This code... does not work :D

B4X:
#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
 

Siam

Active Member
Licensed User
Longtime 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
 

Siam

Active Member
Licensed User
Longtime 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
 

Roycefer

Well-Known Member
Licensed User
Longtime 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.
 
Top