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

JavaAndroid

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

You probably don't have the INTERNET permission. Try adding this to your AndroidManifest.xml file, right before </manifest>:

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

Note: the above doesn't have to be right before the </manifest> tag, but that is a good / correct place to put it.

Note: if this answer doesn't help in your case, read the other answers!

Solution 2 - Java

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.

Solution 3 - Java

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

>Simply Reconnect the wifi will solve the issue.

Solution 4 - Java

>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

Solution 5 - Java

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.

Solution 6 - Java

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.

Solution 7 - Java

"" 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

Solution 8 - Java

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.

Solution 9 - Java

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

Solution 10 - Java

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

Solution 11 - Java

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.

Solution 12 - Java

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

Solution 13 - Java

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.

Solution 14 - Java

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

Solution 15 - Java

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.

Solution 16 - Java

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

Solution 17 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionbejoy georgeView Question on Stackoverflow
Solution 1 - JavaFelixView Answer on Stackoverflow
Solution 2 - JavaEric BrynsvoldView Answer on Stackoverflow
Solution 3 - JavashehzyView Answer on Stackoverflow
Solution 4 - JavadugguView Answer on Stackoverflow
Solution 5 - JavaBatuhan CoşkunView Answer on Stackoverflow
Solution 6 - JavaPablo ValdesView Answer on Stackoverflow
Solution 7 - JavajmjView Answer on Stackoverflow
Solution 8 - JavaFo NkoView Answer on Stackoverflow
Solution 9 - JavaSnicolasView Answer on Stackoverflow
Solution 10 - JavaSummved JainView Answer on Stackoverflow
Solution 11 - JavaEd LeeView Answer on Stackoverflow
Solution 12 - JavaWilliam KinaanView Answer on Stackoverflow
Solution 13 - JavaManoj BeheraView Answer on Stackoverflow
Solution 14 - JavaPaweł RutkowskiView Answer on Stackoverflow
Solution 15 - JavaAlex StylView Answer on Stackoverflow
Solution 16 - JavaTWOcvfanView Answer on Stackoverflow
Solution 17 - JavaChetan ChaudhariView Answer on Stackoverflow