Android Question NetworkOnMainThreadException Error Message in Android Device

junaidahmed

Well-Known Member
Licensed User
Longtime User
I have developed Android application to get data access from Sql server using Http Client.Its working fine in "Android Simulator" but at the same when I run this application in Android Device it shows an error message.Please check attached file and advise how to solve the problem.....
 

Attachments

  • Screenshot_20161019-192302.png
    Screenshot_20161019-192302.png
    136.8 KB · Views: 229

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
I have tried above link to Disable Strict Mode,but it shows an compile error.Please check attached file and advise how to solve the problem.
 

Attachments

  • Untitled.png
    Untitled.png
    235.3 KB · Views: 205
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Thanks Erel...But I didn't get any proper solution.....Please see my below code and convert this code to "HttpUtils2"

Sub Activity_Create(FirstTime As Boolean)
HttpClient12.Initialize("HttpClient12")
LoadGrid("Select * from Arind.Dbo.Color")

End Sub

Sub LoadGrid(Query As String)

Dim request12 As HttpRequest
Dim URL12 As String
URL12 = http://202.89.74.123:85/RemoteDB/ShowGridNew.asp?Param="&Query
request12.InitializeGet(URL12)
request12.Timeout = 10000 'set timeout to 10 seconds
If HttpClient12.Execute(request12, 1) = False Then Return 'Will be false if their is already a running task (with the same id).
ProgressDialogShow("Calling KHARIND server...")
End Sub



Sub HttpClient12_ResponseSuccess (Response As HttpResponse, TaskId As Int)

Log("ResponseSuccess")
ProgressDialogHide
Dim result As String
Dim s As String
Dim Rows() As String
Dim Cols() As String
Dim Header As List
Dim J As Int
result = Response.GetString("UTF8") 'Convert the response to a string

s = result
Rows = Regex.Split("[|]", s)


For i = 0 To Rows.Length - 1
Cols = Regex.Split("[*]", Rows(i))
'DoEvents
'ProgressDialogShow("Calling KHARIND Server........")
Dim Record(Cols.Length) As String
If i = 0 Then
Dim tHeader(Cols(i)) As String
Dim cWidth(Cols(i)) As Int
If Table1.IsInitialized Then
Table1.RemoveView
End If
Table1.Initialize(Me, "Table1", Cols(i),True)
Table1.AddToActivity(PnlRight, 0, 0dip, PnlRight.Width, PnlRight.Height)
'Table1.AddToActivity(Activity, Scale.Right(PnlLeft), 0dip, 100%x - Scale.Right(PnlLeft),PnlLeft.Height)
Table1.ClearAll

Else If i = 1 Then
For J = 0 To Cols.Length - 1
tHeader(J) = Cols(J)
Next
Table1.SetHeader(tHeader)
Else If i = 2 Then
For J = 0 To Cols.Length - 1
If Cols(J) = 135 Then
cWidth(J) = 80dip
Else If Cols(J) = 200 Then
cWidth(J) = 120dip
Else
cWidth(J) = 65dip
End If
Next

Else
For J = 0 To Cols.Length - 1
Record(J) = Cols(J)
Next
Table1.AddRow(Record)
End If
Next
Table1.SetColumnsWidths(cWidth)
ProgressDialogHide


End Sub
Sub HttpClient12_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)

Log(Reason)
Log(StatusCode)
ProgressDialogHide
msg = "Error connecting to server."
If Reason <> Null Then msg = msg & CRLF & Reason
ToastMessageShow (msg, True)

End Sub
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
I am going to clarify only.whether this lib will work or not ????

anyhow we are planning to update current version .....
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Actually I have developed my project using "http lib" in the year of 2012,but when I run my project in Android 6 it shows an error message.

As per "Erel" in above comments (You should use OkHttpUtils2 instead of HttpClient.)

So I have downloaded "OKHttpUtils2"........
 
Upvote 0
Top