216

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.

Community
  • 1
  • 1
bejoy george
  • 29,385
  • 5
  • 19
  • 15
  • can you give the url for which you get this error – Sunil Kumar Sahoo Jun 15 '11 at 09:22
  • 20
    Do you have the `INTERNET` permission? – Felix Jun 15 '11 at 09:30
  • @felix : In my browser i checked the internet connection.it works.HOw can i enable in my application? – bejoy george Jun 15 '11 at 09:40
  • @Octavian : Here i replaced with my original url – bejoy george Jun 15 '11 at 09:40
  • 8
    Make sure that your internet connection is on. – user609239 Jun 15 '11 at 09:59
  • 10
    Check your WiFi connection : ) – Viktor Apoyan Feb 24 '12 at 12:18
  • I got this error when I was testing my app on a device, in a different office with different wifi! The device was simply not automatically connected to the wifi - stupid mistake I made, really :-) – JanB Sep 03 '15 at 07:48
  • You can verify before if isOnline: public boolean isOnline() { ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); return manager.getActiveNetworkInfo() != null && manager.getActiveNetworkInfo().isConnectedOrConnecting(); } – Diego Venâncio Oct 22 '18 at 19:23
  • 4
    Answers are closed but I might point someone in the right direction: For me this was a DNS issue that I need to investigate further. What it meant was I had my hostname that I needed to communicate with, but I was getting the error in the question, and none of the troubleshooting suggested was fixing it. But I am able to ping the hostname. So as a workaround, I am now connecting straight to the IP, but I'll need to investigate further with my employer's IT team why the DNS isn't working as it should. – Chucky Dec 06 '18 at 10:30
  • In my case, I had to use a VPN and that fixed the issue. – steveOS Jun 16 '22 at 08:08

17 Answers17

227

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!

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Felix
  • 88,392
  • 43
  • 149
  • 167
172

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.

Eric Brynsvold
  • 2,880
  • 3
  • 17
  • 22
  • 2
    Thats the actual root of the problem – user606669 Jan 24 '17 at 13:01
  • 1
    I'm encountering this same behavior, but closing/relaunching the emulator isn't fixing anything. But connecting to my work's VPN does... – donut Oct 24 '18 at 23:42
  • This was my problem too, trying some new library to download file. searching here and there for some hour on the library documentation and on the web because it is failed to download the file.. turn out it was the emulator connection problem, lol. It wasting time, but what can I do except laughing lol. Thank you for saving my day – Komang Sidhi Artha Apr 08 '19 at 15:06
  • 3
    Saw this answer and honestly, I did not believe this would be the solution to my problem. Thank you so much Eric! Still curious how you managed to figure this out lol – Roshan Mar 08 '20 at 23:36
  • 2
    I have just wasted 3 hours trying to solve this, really helpful ❤ – mohamed_ashraf51 Jul 21 '21 at 09:54
  • VPN was my issue; I had connected after loading the emulator. – Jimmy Jul 06 '22 at 03:57
  • Android emulator's bug... – Masahiro Aoki Oct 31 '22 at 00:09
  • This was the issue with my one. Thanks – Dinithi Jul 04 '23 at 09:46
84

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

Simply Reconnect the wifi will solve the issue.

shehzy
  • 2,215
  • 3
  • 25
  • 45
46

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

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
duggu
  • 37,851
  • 12
  • 116
  • 113
12

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.

Pablo Valdes
  • 734
  • 8
  • 19
11

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.

Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48
9

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.

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40
Fo Nko
  • 620
  • 10
  • 22
9

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

jmj
  • 237,923
  • 42
  • 401
  • 438
9

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

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40
Snicolas
  • 37,840
  • 15
  • 114
  • 173
  • 1
    Correct 1st you should check browser whether internet is working or not. If still not just wipe the data of emulator and re-run the app. – Adam Noor Feb 02 '22 at 05:37
6

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

Summved Jain
  • 872
  • 2
  • 18
  • 21
4

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.

Ed Lee
  • 187
  • 2
  • 13
4

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

William Kinaan
  • 28,059
  • 20
  • 85
  • 118
4

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

  • How did you resolve it? I have noticed randomly on xyz mobile network at times mobile device only gets IPv4... where my domain work on both network IPv6 and IPv4 from most of network but only on that xyz network doesn't work on IPv4. – Shadow Droid Oct 18 '22 at 06:34
3

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

TWOcvfan
  • 388
  • 1
  • 3
  • 19
2

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.

Alex Styl
  • 3,982
  • 2
  • 28
  • 47
1

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

Chetan Chaudhari
  • 323
  • 5
  • 15
1

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.

Manoj Behera
  • 2,736
  • 22
  • 13
  • 9
    Well, this is like suggesting to take the bus when someone asks why their car is not working. After all, one purpose of hostnames is that the underlying IP address can change anytime. – Manuel Nov 07 '19 at 03:13