Android Question jRDC2 query problem

oscarsarrio

Member
Licensed User
Longtime User
I'm moving everything to this new service ... And so far everything has worked correctly I have several queries working correctly, but in this specific one I get an error that I do not know exactly where it comes from. If the query gives me a result without data it works correctly but if it gives results I skip the error of the log.

(log)

** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 java.lang.RuntimeException: Object should first be initialized (JavaObject).</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /rdc. Reason:
<pre> java.lang.RuntimeException: Object should first be initialized (JavaObject).</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>

(b4a)

B4X:
Sub Login_Click
 
   Dim login_ok As Boolean
 
   ProgressDialogShow2("Espere..",True)
 
   Dim req As DBRequestManager = CreateRequest
   Dim cmd As DBCommand = CreateCommand("select_login",Array(num_serie.Text,login_pass.text))
 
   Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(x As HttpJob)
 
   If x.Success Then (error in this line)
    
       req.HandleJobAsync(x, "req")
       Wait For (req) req_Result(res As DBResult)
    
       For Each row() As Object In res.Rows
    
           login_ok=True
        
       Next
        
   Else
       Msgbox("ERROR: " & x.ErrorMessage,"yo")
   End If
 
   x.Release
 
   ProgressDialogHide
 
   If login_ok =True Then
    
       Msgbox("LOGIN CORRECTO","INFORMACIÓN")
    
       Else
           Msgbox("LOGIN INCORRECTO","INFORMACIÓN")
   End If
 
 
End Sub

Really thx
 
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
B4X:
(b4a)

Sub Login_Click

Dim login_ok As Boolean

ProgressDialogShow2("Espere..",True)

Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand = CreateCommand("select_login",Array(num_serie.Text,login_pass.text))

Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(x As HttpJob)

If x.Success Then (error in this line)

req.HandleJobAsync(x, "req")
Wait For (req) req_Result(res As DBResult)

For Each row() As Object In res.Rows

login_ok=True

Next

Else
Msgbox("ERROR: " & x.ErrorMessage,"yo")
End If

x.Release

ProgressDialogHide

If login_ok =True Then

Msgbox("LOGIN CORRECTO","INFORMACIÓN")

Else
Msgbox("LOGIN INCORRECTO","INFORMACIÓN")
End If


End Sub
so now i can read it.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Make this so:
B4X:
For Each row() As Object In res.Rows

login_ok=True

Next
to
B4X:
if  res.RowsSize > 0 then

login_ok=True

end if

and to this:
B4X:
If x.Success Then (error in this line)
witch version of okHttpUtils2 do you have?
 
Upvote 0

oscarsarrio

Member
Licensed User
Longtime User
Change for:


B4X:
 Dim login_ok As Boolean
 
   ProgressDialogShow2("Espere..",True)
 
   Dim req As DBRequestManager = CreateRequest
   Dim cmd As DBCommand = CreateCommand("select_login",Array(num_serie.Text,login_pass.text))
 
   Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(x As HttpJob)
 
   If x.Success Then
      
       req.HandleJobAsync(x, "req")
       Wait For (req) req_Result(res As DBResult)
      
   If  res.Rows.Size> 0 Then

       login_ok=True

       End If
              
   Else
       Msgbox("ERROR: " & x.ErrorMessage,"yo")
   End If
 
   x.Release
 
   ProgressDialogHide
 
   If login_ok =True Then
      
       Msgbox("LOGIN CORRECTO","INFORMACIÓN")
      
       Else
           Msgbox("LOGIN INCORRECTO","INFORMACIÓN")
   End If


But get same error. Thx
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Please use CODE Tags when posting code
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Have you checked to see if your jRDC2 server is running correctly? Using a browser, where xxx.xxx.xxx.xxx is the IP address/host name of your jRDC2 server and where yyyy is the port of your jRDC2 server what does
B4X:
http://xxx.xxx.xxx.xxx:yyyy/test
produce?
 
Upvote 0

oscarsarrio

Member
Licensed User
Longtime User
Yes, the webservice works correctly, I even make a previous query correctly the problem comes to me in this query, which was working with the previous RDC and with this it gives me this problem.

The complete app code is:

B4X:
#Region  Project Attributes
 #Region  Project Attributes
    #ApplicationLabel: XXX
    #VersionCode: 1
    #VersionName: 1.00
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
    #AdditionalJar: com.android.support:support-v4
    
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Type DBResult (Tag As Object, Columns As Map, Rows As List)
    Type DBCommand (Name As String, Parameters() As Object)
    Private const rdcLink As String = "http://XXX.XXX.XX.XX:178/rdc"

End Sub

Sub Globals
    
    'Generales
    Private estaciones_manual As Spinner
    Private TabStrip1 As TabStrip
    Dim nombres_array(300) As String
    Dim posicion_list (300) As Int
    Dim myABBarcode As ABZxing
    
    'Login
    Private qr_log As Button
    Private num_serie As EditText
    Private Login As Button
    Private login_pass As EditText
    Private EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    Activity.RemoveAllViews
    Activity.LoadLayout("Main")
    TabStrip1.LoadLayout("login", "LOGIN")
    nombres_estacion
    num_serie.text=GetDeviceId
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


'CONSULTAS SQL ------------------------------------------------------------------------------------------------

Sub CreateRequest As DBRequestManager
    Dim req As DBRequestManager
    req.Initialize(Me, rdcLink)
    Return req
End Sub

Sub CreateCommand(Name As String, Parameters() As Object) As DBCommand
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = Name
    If Parameters <> Null Then cmd.Parameters = Parameters
    Return cmd
End Sub

Sub nombres_estacion  ' WORKS FINE
    
    ProgressDialogShow2("Espere..",True)
    
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("select_nombres",Array("1"))
    
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
    
        Dim x As Int=0
        
        For Each row() As Object In res.Rows
        
            estaciones_manual.Add(row(1))
            nombres_array(row(0))=row(1)
            posicion_list(x)=row(0)
            x=x+1
            
        Next
        
        
    Else
        Msgbox("ERROR: " & j.ErrorMessage,"yo")
    End If
    
    j.Release
    
    ProgressDialogHide
    
End Sub

'CODIGO QR EVENTOS ------------------------------------------------------------------------------------------------------

Sub qr_log_Click
    myABBarcode.ABGetBarcode("myabbarcode", "")
End Sub


Sub myABBarcode_BarcodeFound(barCode As String, formatName As String)
    
End Sub

Sub myABBarcode_Canceled
    Msgbox("Canceled","")
End Sub

' LOGIN ---------------------------------------------------------------------------------------------------------------------


Sub Login_Click ' NO WORKS , GIVE ME ERROR 500
    
    Dim login_ok As Boolean
    ProgressDialogShow2("Espere..",True)
    
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("select_login",Array(num_serie.Text,login_pass.text))
    
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(x As HttpJob)
    
    If x.Success Then
        req.HandleJobAsync(x, "req")
        Wait For (req) req_Result(res As DBResult)
        
        For Each row() As Object In res.Rows
        
            login_ok=True
            
        Next
            
    Else
        Msgbox("ERROR: " & x.ErrorMessage,"yo")
    End If
    
    x.Release
    
    ProgressDialogHide
    
    If login_ok =True Then
        
        Msgbox("LOGIN CORRECTO","INFORMACIÓN")
        
        Else
            Msgbox("LOGIN INCORRECTO","INFORMACIÓN")
    End If
    
    
End Sub


'Eventos keypress ------------------------------------------------------------------------------------------------------------
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    
    Dim salgo As Boolean=False
    
    If KeyCode = KeyCodes.KEYCODE_BACK Then
    
        'If info_estados.Visible =True Then
        
        '    info_estados.Visible =False
        '    salgo=True
        '    Return True
        
        'End If
        
        
        If salgo=False Then
            
            Dim result As Int
            result = Msgbox2("Salir de la App?", "labici Usuarios", "Si", "", "No", LoadBitmap(File.DirAssets, "advertencia.png"))

            If result = DialogResponse.Positive Then
            
                ExitApplication
            
            Else:
            
                Return True
            End If
            
        End If
        
    End If

End Sub

'UTILES
Sub GetDeviceId As String
      
    Dim p As Phone
    Dim id As String
    Dim r As Reflector
    Dim Api As Int

    Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
    If Api < 9 Then
        'Old device
        id= p.GetSettings("android_id")
    Else
        'New device
        id= r.GetStaticField("android.os.Build", "SERIAL")
        If id.ToLowerCase = "unknown" Then id= p.GetSettings("android_id")
    End If
    Return id
End Sub
 
Upvote 0

oscarsarrio

Member
Licensed User
Longtime User
The problem comes when an SQL field is in null in this case the date ... There is no option to rectify this ???? ... Greetings and thank you
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Are you using jRDC2 2.21?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Ok. You'll need to modify the source of jRDC2 version 2.21.
In the RDCHandler module, replace
B4X:
Else If DateTimeMethods.ContainsKey(ct) Then
   row(i) = jrs.RunMethodJO(DateTimeMethods.Get(ct), Array(i + 1)).RunMethod("getTime", Null)
Else
with
B4X:
Else If DateTimeMethods.ContainsKey(ct) Then
    row(i) = jrs.RunMethod("getObject", Array(i + 1))
    If row(i) <> Null Then
        row(i) = jrs.RunMethodJO(DateTimeMethods.Get(ct), Array(i + 1)).RunMethod("getTime", Null)
    End If
Else
The original code should start at line 78. If this works for you, I'll post a bug thread (unless @Erel's sees this first).
 
Upvote 0

oscarsarrio

Member
Licensed User
Longtime User
OliverA thank you very much. Now I receive perfectly the value 'null' and I do not get any error in the webservice. Thanks for the support. a greeting
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
What should a Null time value be converted to? It is very bad to automatically convert it to 0.
I'm not converting it to a 0. I'm leaving it as a Null. Looking at the jRDC2 code and doing some testing, the overarching spirit is to return Null for a Null and my code change is in line with that spirit. Please note that I said overarching, not complete, since GetDouble2 breaks that rule by returning 0 for Null. Therefore, jRDC2, as it stands is not consistently handling and returning Nulls. To make it consistent, this
B4X:
Else if ct = 2 Or ct = 3 Then               
   row(i) = rs.GetDouble2(i)
should be changed to
B4X:
Else if ct = 2 Or ct = 3 Then       
   row(i) = jrs.RunMethod("getObject", Array(i + 1))
   If row(i) <> Null Then
      row(i) = rs.GetDouble2(i)
   End If
With this change (and the code change above for date handling), jRDC2 would consistently return Null for Null.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The double behavior will not be changed as it will break backwards compatibility. It also does make more sense to return 0 for null doubles. It is not the same as 0 for time values (0 = 1.1.1970).

I will make the following change:
B4X:
Dim SQLTime As JavaObject = jrs.RunMethodJO(DateTimeMethods.Get(ct), Array(i + 1))
               If SQLTime.IsInitialized Then
                   row(i) = SQLTime.RunMethod("getTime", Null)
               Else
                   row(i) = Null
               End If
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I will make the following change:
I knew there would be a way to do this without calling getObject first. I just forgot about the whole IsInitialized thing for JavaObject, even though I'm sure you just mentioned this in a recent (a couple of days ago?) reply to another question.
 
Upvote 0
Top