user3608352
user3608352

Reputation: 407

java Exception in thread "main" java.net.UnknownHostException: Test: Test: unknown error OS ubuntu

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

but my error is still not resolved.

My code :

import java.net.*;

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

    }
}

Error :

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

Upvotes: 15

Views: 28749

Answers (2)

Dynamic Remo
Dynamic Remo

Reputation: 531

There's a chance that you might be contacting to an external ip address in your application and you are not connected to the internet. So, Check your Internet Connection before making some change to host/dns or any other...

There's also a possibility that you require a VPN Connection to be in the some particular network to access those external url/ip. So, check that too.

Cheers ;-)

Upvotes: 0

hutingung
hutingung

Reputation: 1800

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

Add Sachin to /etc/hosts

myip     localhost
127.0.0.1   localhost
127.0.1.1   test5
127.0.0.1   Sachin

Upvotes: 24

Related Questions