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.