无法解析主机“<在此处插入 URL>"没有与主机名关联的地址 [英] Unable to resolve host "<insert URL here>" No address associated with hostname

查看:37
本文介绍了无法解析主机“<在此处插入 URL>"没有与主机名关联的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试按照本教程进行操作:从网络获取数据

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.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 对其进行了扩展.代码如下:

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.

推荐答案

我敢打赌,您忘记授予您的应用使用互联网的权限.尝试将其添加到您的 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" />

这篇关于无法解析主机“&lt;在此处插入 URL&gt;"没有与主机名关联的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆