Android Question B4XTable error

David Hawkins

Active Member
Licensed User
Longtime User
Hi have a B4XTable which populates perfectly well the first time I use it but produces the following error every time thereafter:
(SQLiteException) android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE data )

When leaving the page the Log shows
closing old db.
which I assume is correct.

I am not using SQLite as a database and the data which is populating the Table is Json converted to a list. I am using
B4X:
B4XTable1.Clear
to clear the table. Do I need to to do anything else to destroy the table before using it again?

Many regards

David
 

David Hawkins

Active Member
Licensed User
Longtime User
Hi Mahares, thank you for your reply the code for populating the B4XTable is below
B4X:
        If Job.Success Then
            Dim parser As JSONParser
            Dim response As String = Job.GetString
            parser.Initialize(response)
            
            Dim R As List = parser.NextArray

            Log(response)
            Dim l As List
            l.Initialize

            For Each colroot As Map In R
                sDuration = colroot.Get("Duration")
                sValue = colroot.Get("Value")
                sWorkType = colroot.Get("WorkType")
                sCompany = colroot.Get("Company")           
                l.Add(Array As String(NumberFormat(sDuration, 0, 2), Formatter.Format(sValue), sWorkType, sCompany))
            Next

        Else
            ToastMessageShow("There has been an error getting data!",True)
        End If
        Job.Release
    Catch
        Log(LastException)
    End Try
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
ode for populating the B4XTable
The code you provided looks sound and does not offer any new tips about the problem. When you run it a second time, you are forgetting to redefine the columns data. See sample below. If you discover otherwise, please attach your project.
B4X:
Private Sub Button1_Click
    B4XTable1.Clear

    'below lines need to be included:
    B4XTable1.AddColumn("Duration",  B4XTable1.COLUMN_TYPE_NUMBERS)  'or what ever data type you use
    B4XTable1.AddColumn("Value",  B4XTable1.COLUMN_TYPE_NUMBERS)         'or what ever data type you use
    B4XTable1.AddColumn("WorkType",  B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("Company",  B4XTable1.COLUMN_TYPE_TEXT)
    'rest of your code to populate the B4XTable from Json
End Sub
 
Upvote 0

David Hawkins

Active Member
Licensed User
Longtime User
Hi Mahares, I am very pleased to report that your suggestion has saved the day, all is working as expected. Thank you for your timely responses.

Regards

David
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…