Android Question java.lang.RuntimeException: java.lang.Exception: Sub db_nonquerycomplete was not found.(resolved)

Vania Contreras

Member
Licensed User
i have this code

B4X:
Sub getTraspasoEntrada
    Dim strquery As String
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("get_traspasos_entrada", Null)
    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)
'        req.PrintTable(res)
     
        If db.IsInitialized = False Then
            db.Initialize(ruta , "siscom.db", True)
        End If
'        createEntradas
        For Each row()  As Object In res.Rows
            strquery = "insert into tENTRADA values (?,?,?,?,?,?,?,?,?,?,?,'','')"
'            strquery = "insert into tENTRADA values ('" & row(0) & "',?','?','?','?',?','?','?','?','?','?')"
            Log(strquery)
            db.AddNonQueryToBatch(strquery,Array(row(0),row(1),row(2),row(3),row(4),row(5),row(6),row(7),row(8),row(9),row(10)))
        Next
        Dim SenderFilter As Object = db.ExecNonQueryBatch("db")
        Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
        Log("NonQuery: " & Success)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub

Sub cmbTentrada_Click
    perate.Visible=True
    getTraspasoEntrada
    MsgboxAsync("Se ha sincronizado los traspasos de entrada activos correctamente","Traspaso de entrada")
    perate.Visible=False
End Sub

and work fine if i call from a button, now i add a service

but when run this code in the service i get this error

java.lang.RuntimeException: java.lang.Exception: Sub db_nonquerycomplete was not found.
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:170)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)


This is my code in the service


B4X:
Sub Process_Globals
    Dim db As SQL
    Dim ruta As String
    Private rp As RuntimePermissions
End Sub

Sub Service_Create
'

End Sub

Sub Service_Start (StartingIntent As Intent)
    getTraspasoEntrada
End Sub

Sub Service_Destroy
  
End Sub

Sub bdLocal As ResumableSub

    Log("Se creara la base ")
    If File.ExternalWritable Then
        ruta=rp.GetSafeDirDefaultExternal("")
    Else
        ruta=File.DirInternal
    End If
    Log(ruta)
'    File.MakeDir(ruta, "almacen/data")
  
    If db.IsInitialized = False Then
        db.Initialize(ruta , "siscom.db", True)
    End If
    db.Close
    Return True
End Sub

Sub getTraspasoEntrada
    bdLocal
    Dim strquery As String
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("get_traspasos_entrada", Null)
    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)
'        req.PrintTable(res)
      
        If db.IsInitialized = False Then
            db.Initialize(ruta , "siscom.db", True)
        End If
'        createEntradas
        For Each row()  As Object In res.Rows
            strquery = "insert into tENTRADA values (?,?,?,?,?,?,?,?,?,?,?,'','')"
            db.AddNonQueryToBatch(strquery,Array(row(0),row(1),row(2),row(3),row(4),row(5),row(6),row(7),row(8),row(9),row(10)))
        Next
        Dim SenderFilter As Object = db.ExecNonQueryBatch("db")
        Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
        Log("NonQuery: " & Success)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub

public Sub CreateRequest As DBRequestManager
    Dim req As DBRequestManager
    req.Initialize(Me, Main.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


i am working with b4a 8.0
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
db_nonquerycomplete was not found.
you did initialize the Database with a Eventprefix db

But you are using a Eventsub with a SQL Prefix.

Dim SenderFilter As Object = db.ExecNonQueryBatch("db")
Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)

Change ExecNonQueryBatch("db") to ExecNonQueryBatch("sql")

OR use
B4X:
Wait For (SenderFilter) DB_NonQueryComplete (Success As Boolean)
 
Upvote 0
Top