I'm trying to get ip address of machine with host name nirranjan-pc
in android and tried using below code as per the answer of this question
Log.e(tag, "In background method :: ");
try {
String ip = InetAddress.getByName("nirranjan-pc").getHostAddress();
Log.e(tag, "++++++++++++ IP FOUND :: " + ip);
} catch (Exception ex) {
Log.e(tag, "Exception:: " + ex);
Log.e(tag, Log.getStackTraceString(ex));
Log.e(tag, "Exception Host ", ex);
} finally {
Log.e(tag, "Finally::");
}
but i was not getting the ip address and unable to get full stack trace of UnknownHostException
using Log.e(tag, Log.getStackTraceString(ex));
and Log.e(tag, "Exception Host ", ex);
methods.
Only Log.e(tag, "Exception:: " + ex);
method works fine.
my logcat is below.
02-23 12:23:24.308 16507-16618/in.gauriinfotech.sevadeal E/Favour: In background method ::
02-23 12:23:24.350 16507-16513/in.gauriinfotech.sevadeal W/art: Suspending all threads took: 14.457ms
02-23 12:23:24.377 16507-16618/in.gauriinfotech.sevadeal E/Favour: Exception:: java.net.UnknownHostException: Unable to resolve host "nirranjan-pc": No address associated with hostname
02-23 12:23:24.380 16507-16618/in.gauriinfotech.sevadeal E/Favour: Exception Host
02-23 12:23:24.380 16507-16618/in.gauriinfotech.sevadeal E/Favour: Finally::
My Question
1) Why Log.e(tag, Log.getStackTraceString(ex));
and Log.e(tag, "Exception Host ", ex);
methods not functioning properly and no giving stack trace.
2) I'm getting correct IP address without any error in java desktop application. Why it is not working in android?
-- Also i tried to access same using Google Chrome browser in android
It works fine with IP address
But not working with Machine Name
AND strange is that, when i try to open website from browser from Windows Phone, it opens with no error.