Hello, sometimes I get the NetworkOnMainThreadException when I run my app... I'm using a Galaxy Nexus with Jelly Bean. The app uses HttpUtils to download data from an online .php page.
I read on the forum that I should use AsyncStreams, but I didn't understand the difference between this and AsyncStreams... Can you explain it?
Thank you in advance.
Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
countWorking = countWorking - 1
finishTasks = finishTasks + 1
HandleError(TaskId, Reason)
If Response <> Null Then
Log(Response.GetString("UTF8"))
Response.Release
End If
ProcessNextTask
End Sub
You can add a Try Catch block to ignore errors related to Response.GetString.
Other options:
- Use HttpUtils2 instead of HttpUtils
- Wait for B4A v2.30. The Http library was updated and this error will not happen.
Thanks for your help Erel, but I didn't understand.. you are showing me a part of code that regards the ResponseError case but the debug says that it happens at "ResponseSuccess"..
The error happens on this line:
B4X:
Sub hc_info_ResponseSuccess(Response As HttpResponse, TaskId As Int)
ProgressDialogHide
statoconnessione = "connesso"
vet_info = Regex.Split(CRLF, Response.GetString("UTF8")) '<- this is the line
sometimes it works.. but in most cases it gives the error...