线程“main” java.net.UnknownHostException: Test: Test: unknown error OS ubuntu 中的 java Exception
此错误与我上一个问题有关,其中我遇到了错误。我发现了一个建议,在中添加一个条目:InetAddress.getLocalHost()
/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