【发布时间】:2013-03-12 23:15:44
【问题描述】:
我有一个问题,如果我尝试 InetAddress.getLocalHost() 甚至 InetAddress.getByName(String host) 它每次都会抛出异常,即使对于像 nba.com 这样的已知网站我有点困惑仅供参考目标设备是一个 android 4.1.1 GS3 和 wifi 和移动网络。代码如下
try{
InetAddress ownIP=InetAddress.getLocalHost();
System.out.println("IP of my Android := "+ownIP.getHostAddress());
}catch (Exception e){
System.out.println("Exception caught ="+e.getMessage());
String t = e.getMessage() + "yes";
}
下面是 System.out
03-12 18:59:52.636: I/System.out(18996): 异常捕获 =null
提前致谢
【问题讨论】:
-
如果
InetAddress.getLocalHost()真的抛出异常,你有一个严重错误配置的hosts文件和/或DNS。
标签: java android network-programming inetaddress