Android Question B4XTable error adding line

makis_best

Active Member
Licensed User
Hi

I try to add a line into B4Xtable getting the info from another table.

My code is
B4X:
B4XTable1.sql1.ExecNonQuery2($"INSERT INTO data VALUES( ?, ?, ?, ?, ?, ?)"$, Array As Object( ItemTable_All_Items.GetValue(0,row), _
ItemTable_All_Items.GetValue(1,row), NumberFormat2(Price1, 1, 0, 4, False), _
NumberFormat2(Quantity1, 1, 0, 2, False), ItemTable_All_Items.GetValue(2,row), _
NumberFormat2(Quantity1*Price1, 1, 0, 2, False)))
If I execute a log() before I execute ExecNonQuery2, log() show my data correctly
B4X:
Log(ItemTable_All_Items.GetValue(0,row) & " - " & ItemTable_All_Items.GetValue(1,row) & " - " & NumberFormat2(Price1, 1, 0, 4, False) & " - " & _
            NumberFormat2(Quantity1, 1, 0, 2, False) & " - " & ItemTable_All_Items.GetValue(2,row) & " - " & NumberFormat2(Quantity1*Price1, 1, 0, 2, False))

But ExecNonQuery2 always return the error
java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.sqlite.SQLiteStatement android.database.sqlite.SQLiteDatabase.compileStatement(java.lang.String)' on a null object reference
Why? What I am doing wrong?
 
Last edited:

Erel

Administrator
Staff member
Licensed User
It is a mistake to use NumberFormat here. Add the real numbers and let B4XTable format them for you.

Have you called SetData on B4XTable1? The database is only created when you call SetData. Note that the db creation is async so it will not be immediately available.
You can wait for it to be ready with:
B4X:
B4XTable1.SetData(data)
Wait For B4XTable1_DataUpdated
'ready here
 
Top