F Francesco Maresca Member Licensed User Longtime User Oct 22, 2015 #1 Hi, I have to go through Java Object array list string. I do this in java: List <String> stocklist = new ArrayList <String> (); stockList.add ("stock1"); stockList.add ("stock2"); stockList.add ("stock3"); stockList.add ("stock4"); stockList.add ("stock5"); stockList.add ("stock6"); MA.setFields (stockist); In b4A I write: Dim stockList As List stockList.Initialize() stockList.add("stock1") stockList.add("stock2") stockList.add("stock3") stockList.add("stock4") stockList.add("stock5") stockList.add("stock6") fb.RunMethod("setFields", Array As Object(stockList) ) But I have this error: Caused by: java.lang.NullPointerException: Attempt to read from null array How can I call this function? I need a different object? Francesco
Hi, I have to go through Java Object array list string. I do this in java: List <String> stocklist = new ArrayList <String> (); stockList.add ("stock1"); stockList.add ("stock2"); stockList.add ("stock3"); stockList.add ("stock4"); stockList.add ("stock5"); stockList.add ("stock6"); MA.setFields (stockist); In b4A I write: Dim stockList As List stockList.Initialize() stockList.add("stock1") stockList.add("stock2") stockList.add("stock3") stockList.add("stock4") stockList.add("stock5") stockList.add("stock6") fb.RunMethod("setFields", Array As Object(stockList) ) But I have this error: Caused by: java.lang.NullPointerException: Attempt to read from null array How can I call this function? I need a different object? Francesco
R Roycefer Well-Known Member Licensed User Longtime User Oct 22, 2015 #2 B4A Lists aren't the same java.util.ArrayLists. Try this: Code: Dim al As JavaObject al.InitializeNewInstance("java.util.ArrayList", Null) al.RunMethod("add", Array("stock1")) al.RunMethod("add", Array("stock2")) fb.RunMethod("setFields", Array As Object(al) ) This is untested code, beware. Upvote 0
B4A Lists aren't the same java.util.ArrayLists. Try this: Code: Dim al As JavaObject al.InitializeNewInstance("java.util.ArrayList", Null) al.RunMethod("add", Array("stock1")) al.RunMethod("add", Array("stock2")) fb.RunMethod("setFields", Array As Object(al) ) This is untested code, beware.
Erel B4X founder Staff member Licensed User Longtime User Oct 23, 2015 #3 Actually the code in the first post should work. B4A List wraps java ArrayList. The problem is somewhere else. Upvote 0
Actually the code in the first post should work. B4A List wraps java ArrayList. The problem is somewhere else.
MMORETTI964 Member Licensed User Longtime User Oct 23, 2015 #4 Erel said: Actually the code in the first post should work. B4A List wraps java ArrayList. The problem is somewhere else. Click to expand... Erel, it seems when B4A create a List (better, when B4A add an item to list), the roomsize of the list (seen on the debugger) is for 12 item. Yes, the size returns correctly the number (1), but... could be the library inside check the List by roomsize within a cycle? AFAYK java takes room for List like B4A does? As expected, the solution given by Roycefer give us the same problem (Attempt to read from null array). Now we try to write an inline java function to create List directly from java and will post the result. Upvote 0
Erel said: Actually the code in the first post should work. B4A List wraps java ArrayList. The problem is somewhere else. Click to expand... Erel, it seems when B4A create a List (better, when B4A add an item to list), the roomsize of the list (seen on the debugger) is for 12 item. Yes, the size returns correctly the number (1), but... could be the library inside check the List by roomsize within a cycle? AFAYK java takes room for List like B4A does? As expected, the solution given by Roycefer give us the same problem (Attempt to read from null array). Now we try to write an inline java function to create List directly from java and will post the result.
Informatix Expert Licensed User Longtime User Oct 23, 2015 #5 What does "setFields" in the first post? Upvote 0
MMORETTI964 Member Licensed User Longtime User Oct 23, 2015 #6 Sorry was an error because we had to initialize the class with a byte array and we doesn't. The first write work perfectly (and in Java too the roomsize after inserting an item of a List is the same as B4A). Thank you all for the replies. Upvote 0
Sorry was an error because we had to initialize the class with a byte array and we doesn't. The first write work perfectly (and in Java too the roomsize after inserting an item of a List is the same as B4A). Thank you all for the replies.