B4J Question Error finding no records

desof

Well-Known Member
Licensed User
Longtime User
Error finding no records

If searching fails the application disappears
closes

It works ok if devuleve some record!

Why?


B4X:
Sub PlayButton_Action
    ExecuteRemoteQuery("SELECT * FROM xxxxxxx WHERE ID_PC  ='" & param1.text & "'",Listado)
End Sub

Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://www.xxxxx.com.ar/xxxx/xxxxx.php", Query)
End Sub

Sub JobDone(Job As HttpJob)
    If Job.Success Then
    Dim res As String 
    Dim tmpNum As String
    Dim tmp As String
     
        res = Job.GetString'("UTF8")
     
        Dim parser As JSONParser
        parser.Initialize(res)
     
        Select Job.JobName
            Case Listado
                Dim COUNTRIES As List
                COUNTRIES = parser.NextArray                         
             
                Dim m As Map
                m = COUNTRIES.Get(0)                         
             
                lbID.text = m.GET("ID_PC") 
                lbNombre.text = m.GET("NOMBRE_PC")
                lbUsuario.text = m.Get("USUARIO")
                '
                lbFecha.text = m.GET("FECHA")
                lbVersion.text = m.Get("VERSION")
                lbMail.text = m.GET("MAIL")
                lbRegistrado.text=m.Get("REGISTRADO")
                lbUsos.Text =m.Get("USOS")
        End Select
        SaveStringExample
    Else
'        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
 

stevel05

Expert
Licensed User
Longtime User
Does it write an error to the log when it crashes?
 
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
Does it write an error to the log when it crashes?

It does not give me absolutely no message. And in the log window says this when the error occurs:

Program started.
Error occurred on line: 102 (main).
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at anywheresoftware.b4a.objects.collections.List.Get(List.java:105)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:468)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:209)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:153)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:69)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:425)
at anywheresoftware.b4a.keywords.Common.access$0(Common.java:405)
at anywheresoftware.b4a.keywords.Common$1.run(Common.java:461)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:744)
 
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
Also add Log(res) to check the server response.

placed log this is the last line that runs!!

Log ("2")

m = COUNTRIES.Get(0)

Log ("3")


B4X:
Program started.
1
2
Error occurred on line: 106 (main).
java.lang...........
...........................
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
From:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

it looks like COUNTRIES is an empty list from which you are trying to get the first element.

add a Log(COUNTRIES.Size) e.g.:

B4X:
COUNTRIES = parser.NextArray
log(COUNTRIES.Size)
 
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
From:



it looks like COUNTRIES is an empty list from which you are trying to get the first element.

add a Log(COUNTRIES.Size) e.g.:

B4X:
COUNTRIES = parser.NextArray
log(COUNTRIES.Size)


OK!!!
THANK YOU

Solved!

B4X:
If COUNTRIES.size <> 0 Then               
                    m = COUNTRIES.Get(0)               
                    lbID.text = m.GET("ID_PC")   
                   
                    lbNombre.text = m.GET("NOMBRE_PC")
                    lbUsuario.text = m.Get("USUARIO")
                    '
                    lbFecha.text = m.GET("FECHA")
                    lbVersion.text = m.Get("VERSION")
                    lbMail.text = m.GET("MAIL")
                    lbRegistrado.text=m.Get("REGISTRADO")
                    lbUsos.text =m.Get("USOS")
End If
 
Upvote 0
Top