I am trying to check if a web service is reachable with an android application.
Within my button click listener is:
try {
InetAddress address = InetAddress.getByName(result); // user input is 'result' (a URL) LINE 73
boolean b = address.isReachable(3000);
String str = String.valueOf(b); // turning the value of the boolean into string
pingResult.setText(str); // value displays as true or false
}
catch (UnknownHostException e) {} // will fill with helpful message later
catch (IOException e) {}
Logcat is displaying:
05-10 15:21:21.390: E/AndroidRuntime(11653): FATAL EXCEPTION: main
05-10 15:21:21.390: E/AndroidRuntime(11653): Process: com.example.c3po, PID: 11653
05-10 15:21:21.390: E/AndroidRuntime(11653): android.os.NetworkOnMainThreadException
05-10 15:21:21.390: E/AndroidRuntime(11653): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
05-10 15:21:21.390: E/AndroidRuntime(11653): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
05-10 15:21:21.390: E/AndroidRuntime(11653): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
05-10 15:21:21.390: E/AndroidRuntime(11653): at java.net.InetAddress.getByName(InetAddress.java:289)
05-10 15:21:21.390: E/AndroidRuntime(11653): at com.example.c3po.MainActivity$2.onClick(MainActivity.java:73)
And some more, line 73 has been commented.
Any ideas where I am going wrong?
Thanks