B4J Question InsertMaps ERROR

powerino

Active Member
Licensed User
Hi everyone, i have this error:

(Exception) java.lang.Exception: java.lang.ClassCastException: class [Ljava.lang.String; cannot be cast to class anywheresoftware.b4a.objects.collections.Map$MyMap ([Ljava.lang.String; is in module java.base of loader 'bootstrap'; anywheresoftware.b4a.objects.collections.Map$MyMap is in unnamed module of loader 'app')

i am trying to fill an empty table (sqlite) by passing a list
 

powerino

Active Member
Licensed User
This is the error:

Waiting for debugger to connect...
Program started.
ExecuteMemoryTable: Select * FROM Persona WHERE strftime('%Y-%m-%d', DataModifica) BETWEEN '2020-02-29' AND '2020-03-08';
Errore nella linea: 141
java.lang.ClassCastException: class [Ljava.lang.String; cannot be cast to class anywheresoftware.b4a.objects.collections.Map$MyMap ([Ljava.lang.String; is in module java.base of loader 'bootstrap'; anywheresoftware.b4a.objects.collections.Map$MyMap is in unnamed module of loader 'app')
at anywheresoftware.b4a.objects.collections.Map.getSize(Map.java:114)
at anywheresoftware.b4a.objects.collections.Map$IterableMap.getSize(Map.java:154)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:64)
at com.guerrinosantoni.database.dbutils._insertmaps(dbutils.java:808)
at com.guerrinosantoni.database.gestione._btnxxx_click(gestione.java:646)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:216)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
(Exception) java.lang.Exception: java.lang.ClassCastException: class [Ljava.lang.String; cannot be cast to class anywheresoftware.b4a.objects.collections.Map$MyMap ([Ljava.lang.String; is in module java.base of loader 'bootstrap'; anywheresoftware.b4a.objects.collections.Map$MyMap is in unnamed module of loader 'app')
(ArrayList) [[Ljava.lang.String;@8062955, [Ljava.lang.String;@5f74425f, [Ljava.lang.String;@2a64848c]


ans this is the code:
B4X:
'Dim oggi As String=""
    Private res As ResultSet
    dati.Clear
        
    DateTime.DateFormat = "yyyy-MM-dd"
    'oggi=DateTime.Date(DateTime.now)


    Dim s As String
    s="Select * FROM Persona WHERE strftime('%Y-%m-%d', DataModifica) BETWEEN '" & data1 & "' AND '" & data2 & "';"
    'lancio la query
    res=Main.sql.ExecQuery(s)
    
    Dim lista As List
    lista.Initialize()
    
    lista = DBUtils.ExecuteMemoryTable(Main.sql, s,Null,0)
    DBUtils.InsertMaps(Main.sql,"Persona2",lista)

error is here, in DBUtils:
For Each col As String In m.Keys
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Many mistakes in this short code.

1. You should use ExecQuery2 with a parameterized query.
2. You shouldn't initialize lista if you assign a different object to the variable on the next line.
3. DBUtils.InsertMaps expects a List where each item is a Map that maps between the columns and the new values.

Worth watching: https://www.b4x.com/etp.html?vimeography_gallery=1&vimeography_video=263187269
 
Upvote 0

powerino

Active Member
Licensed User
Ok for points 1 and 2 ... I had already corrected them, but for point 3 I don't understand: in the library we talk about "ListOfMaps As List", so I passed a list ... instead I have to pass a maps ?
 
Upvote 0
Top