java线程“main”中的异常java.net.UnknownHostException:测试:测试:未知错误OS ubuntu

时间:2014-07-07 13:45:58

标签: java ubuntu

此错误与我之前提出InetAddress.getLocalHost()错误的问题有关。我找到了suggestion/etc/hosts中添加条目:

myip     localhost
127.0.0.1   localhost
127.0.1.1   test5

但我的错误仍未解决。

我的代码:

import java.net.*;

public class InetAddressTest {
    public static void main(String args[]) throws UnknownHostException {
        InetAddress Address = InetAddress.getLocalHost();

    }
}

错误:

Exception in thread "main" java.net.UnknownHostException: Sachin: Sachin: unknown error
    at java.net.InetAddress.getLocalHost(InetAddress.java:1484)
    at InetAddressTest.main(InetAddressTest.java:6)
Caused by: java.net.UnknownHostException: Sachin: unknown error
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302)
    at java.net.InetAddress.getLocalHost(InetAddress.java:1479)
    ... 1 more

2 个答案:

答案 0 :(得分:23)

您的主机名是Sachin。 exception in thread "main" java.net.UnknownHostException: Sachin: Sachin: unknown error显示。

将Sachin添加到/ etc / hosts

myip     localhost
127.0.0.1   localhost
127.0.1.1   test5
127.0.0.1   Sachin

答案 1 :(得分:0)

您可能会在应用程序中联系外部IP地址而您没有连接到互联网。因此,在对主机/ DNS或其他任何内容进行一些更改之前,请检查您的Internet连接......

您还可能需要VPN连接才能访问某些特定网络以访问这些外部URL / IP。所以,检查一下。

干杯; - )