Ashish Agarwal Ashish Agarwal - 2 months ago 41
Java Question

java.net.UnknownHostException: Invalid hostname for server: local

What are the steps I should take to solve the error -

java.net.UnknownHostException: Invalid hostname for server: local


I added the new virtual host name at Android emulator but the result returns to "java.net.UnknownHostException virtualhostname at java.net.InetAddress.lookUpHostByName(InetAddress.java:506)".

When I type my virtualhost URL on my PC, it works on display. Then again, when I ran on Emulator and check on Logcat, I couldn't be able to read or check the HTTP status if 200, 202, or an error code number. It simply returned to "UnknownHostException"

Answer

What the exception is really saying is that there is no known server with the name "local". My guess is that you're trying to connect to your local computer. Try with the hostname "localhost" instead, or perhaps 127.0.0.1/::1 (the last one is IPv6).

From the javadocs:

Thrown to indicate that the IP address of a host could not be determined.

127.0.0.1/::1/"localhost" should always be the loopback interface, so if that doesn't work I'd be really surprised.

If there really is a server called "local" on your network - examine your DNS settings or add it to your hosts file.

Comments