Android Question B4XTable problem

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,

this is my code:

tbl is a B4XTable added with the designer

B4X:
    tbl.AddColumn ("ID",tbl.COLUMN_TYPE_NUMBERS)
    tbl.AddColumn ("Name",tbl.COLUMN_TYPE_TEXT)
    tbl.AddColumn("Datum/Zeit",tbl.COLUMN_TYPE_TEXT)
    Dim t1 As String = "a"
    Dim t2 As String = "b"
    Dim t3 As String = "c"
    Dim l As List
    l.Initialize
    l.AddAll (Array As String (t1,t2,t3))
    tbl.SetData (l)
    tbl.Refresh

The AddColumn works, but at tbl.Setdata the program crashes.

The log says the following:

at b4a.mylocation.sessions.access$000(sessions.java:17)
at b4a.mylocation.sessions$WaitForLayout.run(sessions.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (tracker) Create ***
** Service (tracker) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (sessions) Create, isFirst = true **
Error occurred on line: 676 (B4XTable)
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[]
at b4a.mylocation.b4xtable$ResumableSub_SetData.resume(b4xtable.java:459)
at b4a.mylocation.b4xtable._setdata(b4xtable.java:221)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
at b4a.mylocation.sessions.afterFirstLayout(sessions.java:105)
at b4a.mylocation.sessions.access$000(sessions.java:17)
at b4a.mylocation.sessions$WaitForLayout.run(sessions.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)

Why?
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
 

Mahares

Expert
Licensed User
Longtime User
It will be interesting to see what your final code looks like after the suggestion Willy gave you, the following line in your code does not make sense the way it is:
B4X:
l.AddAll (Array As String (t1,t2,t3))
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
The addall was complete nonsense. I have done some development in B4A 5 years ago and still need to get back on track.

Now I think my code looks quite reasonable, at least it works:

B4X:
    Dim t As String = "select * from sessions order by ID desc limit 1000"
    DateTime.DateFormat="yyyy.MM.dd"
    Private rs As ResultSet
    rs = Tracker.sql1.ExecQuery (t)
    If rs.RowCount > 0 Then
        Dim l As List
        l.Initialize
        Do While rs.NextRow
            l.Add (Array As String (rs.GetString ("ID"),rs.GetString ("name"),rs.GetString("zeit")))
        Loop
        tbl.SetData (l)
        tbl.Refresh
    End If
 
Upvote 0
Top