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

Viewed 755112

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

14 Answers

Try the following :

String url = "http://www.google.com/search?q=java";
URL urlObj = (URL)new URL(url.trim());
HttpURLConnection httpConn = 
(HttpURLConnection)urlObj.openConnection();
httpConn.setRequestMethod("GET");
Integer rescode = httpConn.getResponseCode();
System.out.println(rescode);

Trim() the URL

Connect your mobile with different wifi connection with different service provider. I don't know the exact issue but i could not connect to server with a specific service provider but it work when i connected to other service provider. So try it!

I had this issue in my android app when grabbing an xml file the format of my link was not valid, I reformatted with the full url and it worked.

If you are here because your emulator gives you that Exception, Go to Tools > AVD Manager in your android emulator and Cold boot your Emulator.

I had the same issue.

Restart docker was the fix for me. For some reason it needed a restart, I don´t know why, but it worked.

Related