【发布时间】:2011-12-15 02:38:34
【问题描述】:
在离线工作(即未连接到互联网)时,是否有人在使用 OSX Lion 的 Java 中遇到 Java 的 InetAddress.getLocalHost() 解析问题?
似乎 localhost:127.0.0.1 根本没有解析:
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at java.net.InetAddress.getLocalHost(InetAddress.java:1356)
我的 /etc/hosts 没有什么特别的:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
我怀疑这不是 Java 问题,而是 OSX Lion DNS 解析问题。
有人可以帮忙吗?
如果这不是正确的论坛,我可以在哪里询问?
关于如何在 OSX 级别进一步调试的任何提示?
更新 26/10/2011 - 这可能是 JDK 错误,以下测试:
InetAddress addr;
try {
addr = InetAddress.getLocalHost();
System.out.println("With localhost access: " + addr);
} catch (ArrayIndexOutOfBoundsException e) {
addr = InetAddress.getByName(null);
System.out.println("With reverse lookup: " + addr);
}
离线时会打印以下内容:
With reverse lookup: localhost/127.0.0.1
干杯, 高德
【问题讨论】:
-
ping localhostinTerminal.app显示什么? -
所以你只是打电话给
InetAddress.getLocalHost();,你得到了那个例外吗?哇。这是在 Mac OSX 10.7.X 上的 Java1.6 上?我似乎为我工作。 -
Mac OSX 10.7.2 with JDK: java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03-383-11A511) Java HotSpot(TM) 64-Bit服务器虚拟机(内部版本 20.1-b02-383,混合模式)
标签: java macos dns localhost osx-lion