Android Question Error reading SQLLite tables in application

jalvarez

Member
Licensed User
Longtime User
Hi to everybody!

I'm having a problem with my code, attached is the code, database structure image and IDE error that shows when I want to read a record previously written, please help me to see where I'm wrong, Thanks.

jalvarez

P.S. Erel, please read this thread!

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
~w:1004,main,224
1
main_llenakpi (B4A line: 660)
mtda1 = zcursor.GetInt("Tienda")
android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java:68)
at anywheresoftware.b4a.sql.SQL$CursorWrapper.GetInt(SQL.java:337)
at de.amberhome.slidemenuexample.main._llenakpi(main.java:1566)
at de.amberhome.slidemenuexample.main._slidemenu_click(main.java:2178)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:897)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:839)
at de.amberhome.slidemenuexample.slidemenu._mlistview_itemclick(slidemenu.java:304)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA$1.run(BA.java:293)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)

This routine works fine with the same database, different table:
ccursor=SQL1.ExecQuery("Select * from Tiendas")
If ccursor.RowCount > 0 Then

' si el usuario ya lleno los datos y regresa a la app., se llena el
' formulario con lo que escribió, me posiciono en el 1er registro para llenar el formulario, solo debería haber
' 1 registro de tiendas cada vez.

ccursor.Position = 1
mtda = ccursor.GetInt("Tienda")
msuper = ccursor.GetString("Supervisor")
mcity= ccursor.GetString("Ciudad")
medo= ccursor.GetString("Estado")
mdate = ccursor.GetString("Fecha")
mfolio = ccursor.GetString("Folio")
meval = ccursor.GetInt("EvalFinal")
'NuevaTda_Click
EditTda.Text = mtda
EditSuper.Text = msuper
EditCity.Text = mcity
EditEstado.Text = medo
LblFecha.Text = mdate
LblFolio.Text = DateTime.Date(dt)
LblEvFinVal.Text = meval

This one sends the above error:

Dim mtda1 As Int, mfecha As String, mfolios As String
'Dim Tienda As Int
Dim zcursor As Cursor
zcursor=SQL1.ExecQuery("SELECT Tienda,Fecha,Folio,TotalKPI,Tablero,Valor1,Valor2,Valor3,Valor4,Valor5,Valor6 FROM KPI")
If zcursor.RowCount > 0 Then
Log(zcursor.RowCount)
zcursor.Position = 1
mtda1 = zcursor.GetInt("Tienda")
mfecha = zcursor.GetString("Fecha")
mfolios = zcursor.GetString("Folio")
Label10.Text = zcursor.GetInt("TotalKPI")
Label11.Text = zcursor.GetInt("Tablero")
number1.Text = zcursor.GetInt("Valor1")
number2.Text = zcursor.GetInt("Valor2")
number3.Text = zcursor.GetInt("Valor3")
number4.Text = zcursor.GetInt("Valor4")
number5.Text = zcursor.GetInt("Valor5")
number6.Text = zcursor.GetInt("Valor6")
End If
 

Attachments

  • BaseDatos.png
    BaseDatos.png
    34.2 KB · Views: 274

jalvarez

Member
Licensed User
Longtime User
Hi to everybody!

I'm having a problem with my code, attached is the code, database structure image and IDE error that shows when I want to read a record previously written, please help me to see where I'm wrong, Thanks.

jalvarez

P.S. Erel, please read this thread!

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
~w:1004,main,224
1
main_llenakpi (B4A line: 660)
mtda1 = zcursor.GetInt("Tienda")
android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java:68)
at anywheresoftware.b4a.sql.SQL$CursorWrapper.GetInt(SQL.java:337)
at de.amberhome.slidemenuexample.main._llenakpi(main.java:1566)
at de.amberhome.slidemenuexample.main._slidemenu_click(main.java:2178)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:897)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:839)
at de.amberhome.slidemenuexample.slidemenu._mlistview_itemclick(slidemenu.java:304)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA$1.run(BA.java:293)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)

This routine works fine with the same database, different table:
ccursor=SQL1.ExecQuery("Select * from Tiendas")
If ccursor.RowCount > 0 Then

' si el usuario ya lleno los datos y regresa a la app., se llena el
' formulario con lo que escribió, me posiciono en el 1er registro para llenar el formulario, solo debería haber
' 1 registro de tiendas cada vez.

ccursor.Position = 1
mtda = ccursor.GetInt("Tienda")
msuper = ccursor.GetString("Supervisor")
mcity= ccursor.GetString("Ciudad")
medo= ccursor.GetString("Estado")
mdate = ccursor.GetString("Fecha")
mfolio = ccursor.GetString("Folio")
meval = ccursor.GetInt("EvalFinal")
'NuevaTda_Click
EditTda.Text = mtda
EditSuper.Text = msuper
EditCity.Text = mcity
EditEstado.Text = medo
LblFecha.Text = mdate
LblFolio.Text = DateTime.Date(dt)
LblEvFinVal.Text = meval

This one sends the above error:

Dim mtda1 As Int, mfecha As String, mfolios As String
'Dim Tienda As Int
Dim zcursor As Cursor
zcursor=SQL1.ExecQuery("SELECT Tienda,Fecha,Folio,TotalKPI,Tablero,Valor1,Valor2,Valor3,Valor4,Valor5,Valor6 FROM KPI")
If zcursor.RowCount > 0 Then
Log(zcursor.RowCount)
zcursor.Position = 1
mtda1 = zcursor.GetInt("Tienda")
mfecha = zcursor.GetString("Fecha")
mfolios = zcursor.GetString("Folio")
Label10.Text = zcursor.GetInt("TotalKPI")
Label11.Text = zcursor.GetInt("Tablero")
number1.Text = zcursor.GetInt("Valor1")
number2.Text = zcursor.GetInt("Valor2")
number3.Text = zcursor.GetInt("Valor3")
number4.Text = zcursor.GetInt("Valor4")
number5.Text = zcursor.GetInt("Valor5")
number6.Text = zcursor.GetInt("Valor6")
End If



MohammadNew,

DonManfred
Thank you very much again,
As allways, somebody is up to help like you, I'll appreciate your help today and forever, thanks again! 1000 likes to both.
Best Regards.
 
Upvote 0
Top