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
Short description. UnknownHostException is a common error message in Java applications. This error typically indicates that there was a DNS resolution failure. If a Java application fails to get a valid DNS answer, then it might throw an UnknownHostException error.
I was having the same issue on my mac. I found the issue when I pinged my $HOSTNAME
from terminal and it returned ping: cannot resolve myHostName: Unknown host
.
To resolve:
Do echo $HOSTNAME
on your terminal.
Whatever hostname it shows (lets say myHostName
), try to ping it : ping myHostName
. If it returns ping: cannot resolve myHostName: Unknown host
then add an entry into your /etc/hosts
file.
For that edit /etc/hosts
file and add following:
127.0.0.1 myHostName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With