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

victormedranop

Well-Known Member
Licensed User
Longtime 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.

B4X:
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
 

DonManfred

Expert
Licensed User
Longtime User
Sounds like you are trying to trim a null object...
check trim_string2 and RemoveAccents methods if you get a valid string
 
Upvote 0
Top