Android Question Sqlite / http job / How to improve this function

Discussion in 'Android Questions' started by victormedranop, Aug 22, 2017.

  1. victormedranop

    victormedranop Well-Known Member Licensed User

    Hi, I am having some delay problems with this function.
    some time works some time does not. it use 10 second to fill a table.
    with 1300 registry.

    here the code if some one have give me a better view.

    Code:
    Sub JobDone (Job As HttpJob)
     
     
    Log($"Current time is $DateTime{DateTime.Now}"$)
     
    Dim count As Int = 0
     
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
     
    If Job.Success = True Then
     
    Select Job.JobName
     
    Case "Job1"
     
    Log("JOB 1")
     
    Dim parser As JSONParser
     parser.Initialize(Job.GetString)
     
    Dim root As List = parser.NextArray
     
    For Each colroot As Map In root
     
    'Dim date As String = colroot.Get("date")
     Dim thumb_url As String = colroot.Get("thumb_url")
     
    Dim video_url As String = colroot.Get("video_url")
     
    Dim author As String = colroot.Get("author")
     
    Dim audio_url As String = colroot.Get("audio_url")
     
    Dim title As String = colroot.Get("title")
     
    'Log(title & " , " & author & " , " & thumb_url & " , " & audio_url & " , " & video_url)
     'InsertManyRows(title,author,trim_string2(RemoveAccents(thumb_url)),audio_url,video_url)
    ' query = "INSERT INTO mensajes (titulo,nombre,imagen,audio,video) VALUES ( " & "'" & title & "'" & "," & "'" & author & "'" & "," & "'" & trim_string2(RemoveAccents(thumb_url)) & "'"& "," & "'" & audio_url & "'"& "," & "'" & video_url & "'" & ")"
     ' Log(query)
     Dim NumberOfMatches As Int
     NumberOfMatches = sql1.ExecQuerySingleResult(
    "SELECT id FROM mensajes WHERE titulo like " & "'" & title & "'")
     
    If NumberOfMatches > 0 Then 
     sql1.BeginTransaction
     
    Try
     sql1.ExecNonQuery2(
    "INSERT INTO mensajes (titulo,nombre,imagen,audio,video) VALUES (?, ?, ?,?,?)"Array As Object(title, author, trim_string2(RemoveAccents(thumb_url)),audio_url,video_url))
     count = count + 
    1
     
    Catch
     
    Log(LastException)
     
    End Try
     
    Else
     
     
    End If
     
    Next
     
    Try
     sql1.TransactionSuccessful
     
    Catch
     
    Log(LastException)
     
    End Try
     
     
     
    End Select
     sql1.EndTransaction
     
    Log("cantidad de registros = " & count)
     
    Else
     
    Log("Error: " & Job.ErrorMessage)
     
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
     
    Return
     
    End If
     Job.Release
     
     
    Log($"Current time is $DateTime{DateTime.Now}"$)
     
    End Sub
    some time give me some errors like this:

    start_jobdone (java line: 190)
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference
     
  2. DonManfred

    DonManfred Expert Licensed User

    Sounds like you are trying to trim a null object...
    check trim_string2 and RemoveAccents methods if you get a valid string
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Run your app in debug mode and see which line raises this error.
     
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