Exception on GetHostName(IP As String)

willgeorge

Member
Licensed User
Longtime User
I was trying to use some code I found in the form.

Sub GetHostName(IP As String) As String
Dim r As Reflector
r.Target = r.RunStaticMethod("java.net.InetAddress", "getByName", Array As Object(IP), _
Array As String("java.lang.String"))
If r.Target = Null Then Return "N/A"
Return r.RunMethod("getCanonicalHostName")
End Sub

I receive the following Exception on the line
Return r.RunMethod("getCanonicalHostName")

"LastException android.os.NetworkOnMain ThreadException"

Using:
Sub Activity_Create(FirstTime As Boolean)
'Load the layout file created with the visual designer.
Activity.LoadLayout("10inchportrait")
If FirstTime Then
Server.Initialize(8000, "Server")
If Server.IsInitialized Then
Server.Listen
LabelMsg.Text = "Android is listening for a incomming connection"
End If
infostring = GetHostName("192.168.2.3")
LabelInfo.Text = infostring
End If
EditText1.ForceDoneButton = True
End Sub

New to Android and not sure what to do about Threading issues.

Thank you
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…