本文介绍了java线程“main”中的异常java.net.UnknownHostException:测试:测试:未知错误OS ubuntu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此错误与我之前的问题有关,我在 InetAddress.getLocalHost()时遇到错误。我发现在 / etc / hosts :

This error is related to my previous question where I had an error with InetAddress.getLocalHost(). I found a suggestion to add an entry in /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


推荐答案

您的主机名是Sachin。线程main中的异常java.net.UnknownHostException:Sachin:Sachin:未知错误显示。

Your host name is Sachin. The exception in thread "main" java.net.UnknownHostException: Sachin: Sachin: unknown error show that.

将Sachin添加到/ etc / hosts

Add Sachin to /etc/hosts

myip     localhost
127.0.0.1   localhost
127.0.1.1   test5
127.0.0.1   Sachin

这篇关于java线程“main”中的异常java.net.UnknownHostException:测试:测试:未知错误OS ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 00:47