Bug? [solved] java.lang.ClassCastException with Lists and CallSub

Creideiki

Active Member
Licensed User
Longtime User
I get the following error:

java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.List cannot be cast to java.util.List

What do I do:

I have a Service:
B4X:
Sub Process_Globals
   Dim ToDoList As List
End Sub

Sub Service_Create
   ToDoList.Initialize
End Sub

Sub getAdapterVersion(adap As Object)
   CallSub2(adap, "readVersion", ToDoList)
End Sub

getAdapterVersion is called from the Activity with a class object of a class with the following sub:
B4X:
Sub readVersion(tdl As Object)
   Dim todoList = tdl As List
end sub

The ClassCastException raises in the line
B4X:
Dim todoList = tdl As List

What happens here and what can I do to work around? I can't find anything wrong here; the object is a List from start to end!?
 

warwound

Expert
Licensed User
Longtime User
Shouldn't that be:

B4X:
Dim todoList As List=tdl

Martin.

Sent from my GT-I9300 using Tapatalk 2
 

Creideiki

Active Member
Licensed User
Longtime User
You should change the sub signature to:
B4X:
Sub readVersion(tdl As List)
    Dim todoList = tdl As List
end sub

It is related to List being a wrapper of a Java list.

I thought I could only use Object as argument type when I call a sub via CallSub. I'll give it a try.

What can I use as argument type when calling with CallSub??
 
Top