Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

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

like image 875
Ashish Agarwal Avatar asked Oct 21 '22 07:10

Ashish Agarwal


People also ask

What causes Java net 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.


1 Answers

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:

  1. Do echo $HOSTNAME on your terminal.

  2. 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.

  3. For that edit /etc/hosts file and add following:

    127.0.0.1 myHostName

like image 81
Shobhit Puri Avatar answered Oct 23 '22 21:10

Shobhit Puri