Android Question B4XTable CLearing Data

james_sgp

Active Member
Licensed User
Longtime User
This is a bit of a beginner quesiton, but suddenly I can seem to clear the existing data in a B4XTable. When I try and use details_tbl.ClearDataView it throws an error:

B4X:
Error occurred on line: 404 (B4XTable)
java.lang.RuntimeException: Object should first be initialized.
    at anywheresoftware.b4a.sql.SQL.checkNull(SQL.java:55)
    at anywheresoftware.b4a.sql.SQL.ExecQuerySingleResult2(SQL.java:244)
    at anywheresoftware.b4a.sql.SQL.ExecQuerySingleResult(SQL.java:234)
    at b4a.example.b4xtable._cleardataview(b4xtable.java:552)
    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 anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
    at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1717)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

Any help, much appreciated.
 

james_sgp

Active Member
Licensed User
Longtime User
Apologies, but my code to clear the table is one line...
FYI, filling table works without problem.

B4X:
details_tbl.ClearDataView
 
Upvote 0

Chris2

Active Member
Licensed User
The method to clear the data from a B4XTable is
B4X:
b4xtable.Clear

ClearDataView is to do with filtering the data I think
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Apologies, but my code to clear the table is one line...
FYI, filling table works without problem.

B4X:
details_tbl.ClearDataView
The information is not enough.
Make a small project, try details_tbl.ClearDataView
 
Upvote 0

teddybear

Well-Known Member
Licensed User
The method to clear the data from a B4XTable is
B4X:
b4xtable.Clear

ClearDataView is to do with filtering the data I think
No, if you delete some rows it will update the rows count.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Apologies, but my code to clear the table is one line...
FYI, filling table works without problem.

B4X:
details_tbl.ClearDataView
Apologies, I can't read your screen or mind.

I also want to refuse to provide more lines of code but I didn't.

Here how I do normally.

B4X:
B4XTable1.sql1.ExecNonQuery2($"INSERT INTO data VALUES(?, ?, ?, ?)"$, params)
B4XTable1.ClearDataView

B4X:
B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))
B4XTable1.UpdateTableCounters
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
The reason that everyone wants to see more code, @james_sgp, is because the error may be detected at line 404 but your coding error is somewhere else.
B4X:
details_tbl.ClearDataView
Assuming that this is line 404, the error is that details_tbl is not initialised. So why is that? If as you say "suddenly I can[not] seem to clear the existing data in a B4XTable" then we presume the code was working but you have made a coding change somewhere that breaks it. That is what you need to find, and it is not in the code sample (such as it is) that you have provided. You are not going to get anywhere by studying line 404.
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Still can`t get it to work, here is a small sample; as requested. Press refresh button should change the data, but it give an error, that Table isn`t initialised.


James
 

Attachments

  • test1.zip
    11.9 KB · Views: 71
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Still can`t get it to work,
Replace your two subs with these two subs with the same name. It should do it for you:
Please note that I replaced your query with a parameterized query and used aliases for your table names to make it neater, but your query the way it is is also fine.
B4X:
Sub update_detail(id As String)
    Dim Data As List
    DateTime.DateFormat = "dd-MMM-yy, HH:mm"
    Data.Initialize
           
'    Dim rs As ResultSet = sql_gear.ExecQuery("SELECT gear_moves.qr_code, gear_moves.state, gear_moves.date, gear_moves.who, gear_moves.note, gear_moves.sync, gear_items.size FROM gear_items INNER JOIN gear_moves ON gear_items.qr_code = gear_moves.qr_code WHERE ((gear_items.type)='" & id & "');")' ORDER BY id DESC")
'    Dim rs As ResultSet = sql_gear.ExecQuery("SELECT GM.qr_code, GM.state, GM.date, GM.who, GM.note, GM.sync, GI.size FROM gear_items GI INNER JOIN gear_moves GM ON GI.qr_code = GM.qr_code WHERE ((GI.type)='" & id & "');")' ORDER BY id DESC")
    Dim rs As ResultSet = sql_gear.ExecQuery2("SELECT GM.qr_code, GM.state, GM.date, GM.who, GM.note, GM.sync, GI.size FROM gear_items GI INNER JOIN gear_moves GM ON GI.qr_code = GM.qr_code WHERE GI.type= ? ", Array As String( id))
    Log("row count: " & rs.RowCount)
    If rs.RowCount > 0 Then
        Do While rs.NextRow
            Dim row(4) As Object
            If id = "BCD" Or id = "Wetsuit" Then
                row(0) = rs.GetString("gear_items.size")
            Else
                row(0) = "-"
            End If
            row(1) = rs.GetString("gear_moves.state")
            row(2) = DateTime.Date(rs.GetString("gear_moves.date"))
            row(3) = rs.GetString("gear_moves.who")
            Data.Add(row)
        Loop
        rs.Close
        details_tbl.SetData(Data)
    Else
'        If details_tbl.Size > 0 Then details_tbl.ClearDataView
        Log("table size: " & details_tbl.Size)
        details_tbl.refresh       
    End If
End Sub

Private Sub Button1_Click
    details_tbl.Clear
    details_Column(0) = details_tbl.AddColumn("DETAILS", details_tbl.COLUMN_TYPE_TEXT)
    details_Column(1) = details_tbl.AddColumn("STATUS", details_tbl.COLUMN_TYPE_TEXT)
    details_Column(2) = details_tbl.AddColumn("DATE", details_tbl.COLUMN_TYPE_TEXT)
    details_Column(3) = details_tbl.AddColumn("WHO", details_tbl.COLUMN_TYPE_TEXT)
    details_Column(0).Width = 20%x
    details_Column(1).Width = 18%x
    details_Column(2).Width = 20%x
    details_Column(2).Width = 25%x

    update_detail("Reg")
End Sub
 
Last edited:
Upvote 0
Top