I have a simple library that returns a B4X List of Lists, here is a snippet of the library.
When executed from B4J like this it throws an error;
The error is;
java.lang.ClassCastException: class anywheresoftware.b4a.objects.collections.List cannot be cast to class java.util.List (anywheresoftware.b4a.objects.collections.List is in unnamed module of loader 'app'; java.util.List is in module java.base of loader 'bootstrap')
Looking at the Java src for the B4J project it seems to be assuming the child object is a Java List rather than a B4X List.
Not sure whether this is a bug or intended behaviour?
BTW I have worked around this for now by using "ArrayList<ArrayList<String>" instead of List which works fine in B4J.
Java:
package nz.ope.test;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.keywords.Common;
import anywheresoftware.b4a.objects.collections.Map;
import anywheresoftware.b4a.objects.collections.List;
@ShortName("ListList")
public class ListList {
boolean IsInitialised = false;
public void Initialize() {
try {
IsInitialised = true;
} catch (Exception e) {
Common.Log(e.toString());
IsInitialised = false;
}
}
public List Test() {
List parent = new List();
parent.Initialize();
List child1 = new List();
child1.Initialize();
child1.Add("A");
child1.Add("B");
child1.Add("C");
List child2 = new List();
child2.Initialize();
child2.Add("A");
child2.Add("B");
child2.Add("C");
parent.Add(child1);
parent.Add(child2);
return parent;
}
}
When executed from B4J like this it throws an error;
B4X:
Sub AppStart (Args() As String)
Dim L As ListList
L.Initialize
Dim parent As List = L.Test
Dim child1 As List = parent.Get(0)
Dim child2 As List = parent.Get(1)
Log("Hello world!!!")
End Sub
The error is;
java.lang.ClassCastException: class anywheresoftware.b4a.objects.collections.List cannot be cast to class java.util.List (anywheresoftware.b4a.objects.collections.List is in unnamed module of loader 'app'; java.util.List is in module java.base of loader 'bootstrap')
Looking at the Java src for the B4J project it seems to be assuming the child object is a Java List rather than a B4X List.
Java:
_child1 = new anywheresoftware.b4a.objects.collections.List();
_child1 = (anywheresoftware.b4a.objects.collections.List) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), (java.util.List)(_parent.Get((int) (0))));
Not sure whether this is a bug or intended behaviour?
BTW I have worked around this for now by using "ArrayList<ArrayList<String>" instead of List which works fine in B4J.
Last edited: