Android Question jRDC2 query problem

Discussion in 'Android Questions' started by oscarsarrio, Oct 23, 2018.

  1. oscarsarrio

    oscarsarrio Member Licensed 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)

    Code:
    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, 0Null)) 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: Oct 23, 2018
  2. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    Code:
    (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, 0Null)) 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.
     
  3. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    Make this so:
    Code:
    For Each row() As Object In res.Rows

    login_ok=
    True

    Next
    to
    Code:
    if  res.RowsSize > 0 then

    login_ok=
    True

    end if
    and to this:
    Code:
    If x.Success Then (error in this line)
    witch version of okHttpUtils2 do you have?
     
  4. oscarsarrio

    oscarsarrio Member Licensed User

    I use 2.70 okHttpUtils2 ... If change code get a error... Thanks 4 help
     
  5. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    i forgot a "."
    Code:
    res.RowsSize
    to
    Code:
    res.Rows.Size
     
  6. oscarsarrio

    oscarsarrio Member Licensed User

    Change for:


    Code:
    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, 0Null)) 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: Oct 23, 2018
  7. DonManfred

    DonManfred Expert Licensed User

    Please use CODE Tags when posting code
     
    BillMeyer likes this.
  8. OliverA

    OliverA Expert Licensed 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
    Code:
    http://xxx.xxx.xxx.xxx:yyyy/test
    produce?
     
  9. oscarsarrio

    oscarsarrio Member Licensed 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:

    Code:
    #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(300As String
        
    Dim posicion_list (300As 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, 0Null)) 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, 0Null)) 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
     
  10. oscarsarrio

    oscarsarrio Member Licensed 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
     
  11. OliverA

    OliverA Expert Licensed User

    Are you using jRDC2 2.21?
     
  12. OliverA

    OliverA Expert Licensed User

    Ok. You'll need to modify the source of jRDC2 version 2.21.
    In the RDCHandler module, replace
    Code:
    Else If DateTimeMethods.ContainsKey(ct) Then
       row(i) = jrs.RunMethodJO(DateTimeMethods.Get(ct), 
    Array(i + 1)).RunMethod("getTime"Null)
    Else
    with
    Code:
    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).
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that it is a bug. What should a Null time value be converted to? It is very bad to automatically convert it to 0. It is better to let the developer handle it by casting the Null to whichever value that makes sense for them in the query itself.
     
  14. oscarsarrio

    oscarsarrio Member Licensed 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
     
  15. OliverA

    OliverA Expert Licensed User

    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
    Code:
    Else if ct = 2 Or ct = 3 Then               
       row(i) = rs.GetDouble2(i)
    should be changed to
    Code:
    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.
     
  16. Erel

    Erel Administrator Staff Member Licensed 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:
    Code:
    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
     
    jimmyF and OliverA like this.
  17. OliverA

    OliverA Expert Licensed User

    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.
     
  18. oscarsarrio

    oscarsarrio Member Licensed User

    Thanks... All is working perfect.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice