Mashiane Expert Licensed User Longtime User Aug 7, 2018 #1 Hi there I'd like to pass a list and a map to a JavaOject and then iterate these inside my Inline Java. This is what I have tried so far where my paras is defined and initialized as a list. B4X: NativeMe.RunMethod("CreateDocument", Array As Object(path,paras)) Then I added this... B4X: #If Java import anywheresoftware.b4a.objects.collections.Map; import anywheresoftware.b4a.objects.collections.List; With my sub to be called inside by b4j app B4X: public void CreateDocument(String docFile,List pList) Thing is, running.. B4X: NativeMe.RunMethod("CreateDocument", Array As Object(path,paras)) is giving me an error B4X: java.lang.RuntimeException: Method: CreateDocument not matched.
Hi there I'd like to pass a list and a map to a JavaOject and then iterate these inside my Inline Java. This is what I have tried so far where my paras is defined and initialized as a list. B4X: NativeMe.RunMethod("CreateDocument", Array As Object(path,paras)) Then I added this... B4X: #If Java import anywheresoftware.b4a.objects.collections.Map; import anywheresoftware.b4a.objects.collections.List; With my sub to be called inside by b4j app B4X: public void CreateDocument(String docFile,List pList) Thing is, running.. B4X: NativeMe.RunMethod("CreateDocument", Array As Object(path,paras)) is giving me an error B4X: java.lang.RuntimeException: Method: CreateDocument not matched.
stevel05 Expert Licensed User Longtime User Aug 7, 2018 #2 The List in B4j is an ArrayList object (java.util.ArrayList) unless you initialize it with an Array To find the type : B4X: Dim L As List L.Initialize Log(GetType(L)) The java sub will probably need to be declared static. To iterate over the ArrayList in java : B4X: #If Java import java.util.ArrayList; import java.util.Iterator; public static void CreateDocument(String docFile, ArrayList pList){ Iterator iterator = pList.iterator(); while (iterator.hasNext()){ BA.Log((String)iterator.next()); } } #End If Last edited: Aug 7, 2018 Upvote 0
The List in B4j is an ArrayList object (java.util.ArrayList) unless you initialize it with an Array To find the type : B4X: Dim L As List L.Initialize Log(GetType(L)) The java sub will probably need to be declared static. To iterate over the ArrayList in java : B4X: #If Java import java.util.ArrayList; import java.util.Iterator; public static void CreateDocument(String docFile, ArrayList pList){ Iterator iterator = pList.iterator(); while (iterator.hasNext()){ BA.Log((String)iterator.next()); } } #End If