Unable to resolve host "<insert URL here>" No address associated with hostname
I tried following this tutorial: Getting Data from the Web
I tried implementing it on Android 3.0, the latest platform for tablets, however, I get this error: "Unable to resolve host "www.anddev.org" No address associated with hostname."
You can checkout the URL that I used just to prove that the file exists. http://www.anddev.org/images/tut/basic/getdatafromtheweb/loadme.txt
I created a private class and extended it with asynctask. Here is the code:
private class Downloader extends AsyncTask<String,Void,String>{
String myString = null;
@Override
protected String doInBackground(String... arg0) {
try{
URL myURL = new URL("http://www.anddev.org/images/tut/basic/getdatafromtheweb/loadme.txt");
URLConnection ucon = myURL.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while((current=bis.read())!=-1){
baf.append((byte)current);
}
myString = new String (baf.toByteArray());
}catch(Exception e){
myString = e.getMessage();
}
return myString;
}
@Override
protected void onPostExecute(String result){
tv.setText(result);
}
}
Any help out there would be appreciated.
My bet is that you forgot to give your app the permission to use the internet. Try adding this to your android manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Please, check if you have valid internet connection.
May you have taken permission
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
BUT
You may have forgot to TURN ON Internet in Mobile or Whatever Device.
Are you able to reach that url from within the built-in browser?
If not, it means that your network setup is not correct. If you are in the emulator, you may have a look at the networking section of the docs.
If you are on OS/X, the emulator is using "the first" interface, en0 even if you are on wireless (en1), as en0 without a cable is still marked as up. You can issue ifconfig en0 down
and restart the emulator. I think I have read about similar behavior on Windows.
If you are on Wifi/3G, call your network provider for the correct DNS settings.
if you have USB internet like me the emulator seems to dislike connection being turned on and off so you may need to restart the emulator