This is a list of possible solutions to the error:
java.net.UnknownHostException: myapp.co.uk at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
when trying to access a website on Android.
They run from most to least likely, start at the top and work your way down:
- Check that you have <uses-permission android:name=”android.permission.INTERNET” /> set in your AndroidManifest.xml file (on the same level as application tag)
- If you are behind a proxy you may need to do the following:
System.setProperty("http.proxyHost", "my.proxyhost.com"); System.setProperty("http.proxyPort", "1234");
- If you are using an emulator try deleting and recreating the virtual device.
- If you are on a real device try switching the wifi on and then off again
- If it is something which happens once when an emulator or device boots but is ok later you could try ‘warming up’ the dns by running code such as the following before your own web request :
try { InetAddress address = InetAddress.getByName(Url); } catch (UnknownHostException e) { e.printStackTrace(); }
- Try rebooting your development machine – I’ve heard of this working
If none of the above work and you find another solution then let me know.
There are some tips on this link too, just in case.
http://hubpages.com/hub/Tips-to-solve-the-UnknownHostException-on-Android
Make sure you aren’t trying to pass the http:// prefix. Silly.
I spent hours tearing my hair out. I tried your solution and it worked. First words out of my mouth when it worked: “YOU GOTTA BE #@$%^#@ KIDDING ME!”
Thanks for sharing this. =)
There is one more possible solution.
When i have tested my application on real device locally, i have created domain “test” and passed as Url. But you MUST define as domain of second level, for example “test.zz” (there must be dot).
hj
oh my gosh! i have been struggeling on uploading a picture to my server and changing the manifest was the solution. thanks for your help thanks a lot !
Rebooting and creating a new emulator worked for me.. Mine is working with the prefix “http” …
Buenas tardes, no se si ustedes me puedan ayudar o al menos me podrian indicar que debo hacer, y es lo siguente mi cuenta de facebook me aparecio inhabilitada por un phishing no se que sera eso y deseo habilitarla,les agradesco su respuesta ,
How to get my confrmtion code
Number 5 worked for me 🙂 Thanks!