[java] Unable to resolve host "<URL here>" No address associated with host name

In my Android application for reading RSS links, I am getting this error:

java.net.UnknownHostException: Unable to resolve host "example.com"; No address associated with hostname.

In my emulator I can connect to Google through a browser. Please help me to resolve this issue.

This question is related to java android

The answer is


In my case problem was with WIFI working with IPV6 and my domain did not have IPv6 adress


Unable to resolve host “”; No address associated with hostname

I had this issue and I solved it by this way. change

http://hostname/abc/def/ghi/name.php

to

http://ipaddress/abc/def/ghi/name.php //http://97.68.XX.YY/abc/def/ghi/name.php

I solved this by this way...you have to give server ip address instead of hostname/servername.

Please try this and comment your feedback.


In my case, I had that error when I'm connected to VPN on my host but not on simulator. Turning the VPN off solved the issue


Check you have:

1- Access to Internet connectivity.

2- The permission for internet is present in the manifest.

3- The url host is valid and registered in a trusted domain name server.


Unable to resolve host “”; No address associated with hostname

you must have to check below code here on your manifest :

<uses-permission android:name="android.permission.INTERNET" />

and most important at least for me:-

enabled wifi connection or internet connection on your mobile device


It's not your fault bae, I've had this happen sometimes when the emulator's in a weird state. Just restarting the emulator helped me.


It is WiFi bug due to wifi disable or not properly connected.

Simply Reconnect the wifi will solve the issue.


"" it seems you are trying to resolve this host , which is invalid.

Check for rss URL

Update Following are the possibilities

1 Your browser is configured with proxy, app not

System.setProperty("http.proxyHost", "my.proxyhost.com");
System.setProperty("http.proxyPort", "1234");

2 Your browser has access to internet. not app

3 can be an SSL issue if URL is secured


I've seen this problem in the emulator as well. In my case, it is caused by launching the emulator, then putting the computer to sleep or changing the network connection (going from work to home, etc), then attempting to use the same emulator again. Closing and re-launching the emulator resolves the problem in this case.


It could be due to below reasons: -

  1. Either you dont have INTERNET permission in manifest file. If so then please use this statement <uses-permission android:name="android.permission.INTERNET" />

  2. Or you are connected to a network but your internet connection is not working. Like you are connected to a Wi-Fi but it doesnt have internet connection or Mobile data on your phone is ON but you dont have data connectivity on your phone.

Point# 2 is interesting and its not assumption, I have tested the same at my end.

Hope this will help you

Summved


If you are running the app on an emulator, make sure that it is properly connected to the internet. If it is not, the easiest way of solving it is reopening the emulator or creating a new device.


Check permission for INTERNET in mainfest file and check network connectivity.


Sometimes, although you add <uses-permission android:name="android.permission.INTERNET" /> in the AndroidManifest and you have a WiFi connection, this exception can be thrown. In my case, I have turned off WiFi and then turned it on again. This resolved the error. Weird solution, but sometimes it works.


I had the same issue. My virtual device was showing a crossed-out WiFi icon at the top bar of the device. I rebooted the virtual device and everything was back to normal.


Some times on the emulator, I have to launch the browser before my app can access the Internet.


I Had the same problem, and it was because the simulator somehow got in airplane mode, once this was disabled my App worked fine :-) I had tried everything, rebuild, clean+build and reboot android studio and reboot the computer, even reinstalling android studio..