无法解析主机&QUOT;&LT;此处&GT插入URL;&QUOT;没有与主机名关联的地址 [英] Unable to resolve host "<insert URL here>" No address associated with hostname
问题描述
我试过下面这个教程: <一href="http://www.anddev.org/novice-tutorials-f8/getting-data-from-the-web-urlconnection-via-http-t351.html">Getting从Web 数据
I tried following this tutorial: Getting Data from the Web
不过,我试图在Android 3.0,为平板电脑最新的平台实现它,我得到这个错误:无法解析主机www.anddev.org没有与主机名关联的地址。
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."
您可以检出,我只是用来证明文件存在的URL。 <一href="http://www.anddev.org/images/tut/basic/getdatafromtheweb/loadme.txt">http://www.anddev.org/images/tut/basic/getdatafromtheweb/loadme.txt
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
我创建了一个私有类和AsyncTask的扩展它。这里是code:
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);
}
}
任何帮助,在那里将AP preciated。
Any help out there would be appreciated.
推荐答案
我敢打赌,你忘了给您的应用程序使用互联网的权限。尝试添加到您的Android清单:
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" />
这篇关于无法解析主机&QUOT;&LT;此处&GT插入URL;&QUOT;没有与主机名关联的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!