【问题标题】:java Exception in thread "main" java.net.UnknownHostException: Test: Test: unknown error OS ubuntu线程“main”java.net.UnknownHostException中的java异常:测试:测试:未知错误操作系统ubuntu
【发布时间】:2014-07-07 13:45:57
【问题描述】:

这个错误与我之前的问题有关,我在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

【问题讨论】:

    标签: java ubuntu


    【解决方案1】:

    您的主机名是 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
    

    【讨论】:

      【解决方案2】:

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

      您还可能需要在某个特定网络中建立 VPN 连接才能访问这些外部 url/ip。所以,也检查一下。

      干杯 ;-)

      【讨论】:

        猜你喜欢
        • 2014-08-27
        • 1970-01-01
        • 1970-01-01
        • 2018-10-15
        • 2023-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-05
        相关资源
        最近更新 更多