Java - UnknownHostException

时间:2011-06-09 15:17:44

标签: java

专用Linux服务器抛出UnknownHostException。

InetAddress addr;
    try {
        addr = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        throw new InstantiationError("cannot find hub ip");
    }

2 个答案:

答案 0 :(得分:3)

您可能没有localhost {win} /etc/hosts(linux)中system32\drivers\etc\hosts的映射

答案 1 :(得分:0)

我找到的另一个选项就是这个(我喜欢,因为我现在不必在两个文件中重复主机名)...

java getLocalHost() UnknownHostException /etc/hosts file differs linux api?