Helo everyone!
I have a Standart Class Called Productos like this:
This Class uses another Standart Class called Producto like this:
Next I've instantiated the Productos Class in my Main Activity in order to use the list in my BXTable but... It doesn't work: I've done this in my Main Activity:
But the app crashes "error on line 97(Main)
java.lang.NumberFormatException: For input String "id"
I'v changed this and I tried with a For each on listaDatos but it crashes. The log (Log(listaDatos) is retreiving data:
I've tried with a For Next as well but it's still crashing . I don't know what I'm doing wrong. If you notice the Public Sub SelectAll(without Filter in this case) is returning a List so I can't understand
why it doesn't work for my BXTable.
I've changed it putting a Resultset but it crashes saying it can not cast the list with a cursor, and putting a Do While on it.. nothing seems work
I'm working with DBUtils and a Sqlite Database
Thank you
I have a Standart Class Called Productos like this:
B4X:
Public Sub SelectAll(Filtro As String) As List
Dim Cursor As Cursor
Dim Data As List
Data.Initialize()
Cursor = Connection.mySQL.ExecQuery2("SELECT * FROM productos WHERE NombreProd LIKE ?", Array As String("%" & Filtro & "%"))
For i = 0 To Cursor.RowCount -1 Step 1
Cursor.Position = i
Dim Record As Producto
Record.Id = Cursor.GetInt("IdProd")
Record.Nombre = Cursor.GetString("NombreProd")
Record.Precio = Cursor.GetDouble("PrecioProd")
Record.Stock = Cursor.GetInt("Stock")
Data.Add(Record)
Next
Return Data
End Sub
This Class uses another Standart Class called Producto like this:
B4X:
Sub Class_Globals
Public Id As Int
Public Nombre As String
Public Precio As Double
Public Stock As Int
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub
Next I've instantiated the Productos Class in my Main Activity in order to use the list in my BXTable but... It doesn't work: I've done this in my Main Activity:
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Prods As Productos
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("mainly")
If FirstTime Then
CopyDBIfNeeded("bdtest.db")
Connection.mySQL.Initialize(File.DirInternal, "bdtest.db", False)
End If
Prods.Initialize
MostrarProductos
End Sub
Sub MostrarProductos
Dim listaDatos As List = Array As Object(Prods.SelectAll(""))
Log(listaDatos)
TBLProductos.AddColumn("ID",TBLProductos.COLUMN_TYPE_NUMBERS).Width = 20
TBLProductos.AddColumn("NOMBRE PROD", TBLProductos.COLUMN_TYPE_TEXT)
NumberColumn =TBLProductos.AddColumn("PRECIO", TBLProductos.COLUMN_TYPE_NUMBERS)
CreateCustomFormat(NumberColumn)
TBLProductos.AddColumn("STOCK ", TBLProductos.COLUMN_TYPE_NUMBERS)
Dim Row As Producto
Dim Lista As List
Lista.Initialize
Row.Id = listaDatos.Get("id")
Row.Nombre = listaDatos.Get("nombre")
Row.Precio = listaDatos.Get("precio")
Row.Stock = listaDatos.Get("stock")
Lista.Add(Row)
TBLProductos.SetData(Lista)
End Sub
But the app crashes "error on line 97(Main)
java.lang.NumberFormatException: For input String "id"
I'v changed this and I tried with a For each on listaDatos but it crashes. The log (Log(listaDatos) is retreiving data:
B4X:
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(ArrayList) [[[connection=null, dateutils=null, dbutils=null
, edproductos=null, id=1, main=null
, nombre=Toy1, precio=33.0, starter=null
, stock=100], [connection=null, dateutils=null, dbutils=null
, edproductos=null, id=2, main=null
, nombre=Toy2, precio=44.44, starter=null
, stock=89]]]
Error occurred on line: 97 (Main)
java.lang.NumberFormatException: For input string: "id"
I've tried with a For Next as well but it's still crashing . I don't know what I'm doing wrong. If you notice the Public Sub SelectAll(without Filter in this case) is returning a List so I can't understand
why it doesn't work for my BXTable.
I've changed it putting a Resultset but it crashes saying it can not cast the list with a cursor, and putting a Do While on it.. nothing seems work
I'm working with DBUtils and a Sqlite Database
Thank you