Android Question seach logs (error)

MohammadNew

Active Member
Licensed User
Longtime User
B4X:
this is working good >

Sub ListView1_ItemClick (Position As Int, Value As Object)
        cmd= SQL1.ExecQuery("select * from tbl1")
        cmd.Position = Position                   
                       
        EditText1.text = cmd.getString("id")
        EditText2.text = cmd.getString("fname")   
        Spinner1.SelectedIndex =cmd.getString("address")   
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
but this does not work >

Sub btnsearch_Click
cmd= SQL1.ExecQuery("select * from tbl1 where id = '" & EditText1.Text & "'")
           
    If cmd.RowCount > 0 Then
       
        EditText1.text = cmd.GetString("id")
        EditText2.text = cmd.getString("fname")   
        Spinner1.SelectedIndex =cmd.getString("address")
           
    Else
        ToastMessageShow ("not found",True)                       
    End If
End Sub

the logs >

B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 183 (Main)
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.getString(AbstractWindowedCursor.java:50)
    at anywheresoftware.b4a.sql.SQL$CursorWrapper.GetString(SQL.java:355)
    at b4a.example.main._btnsearch_click(main.java:631)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:5210)
    at android.view.View$PerformClick.run(View.java:20976)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6220)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
** Activity (main) Pause, UserClosed = true **
 
Top