public void createXmlResource(String city, OutputStream out) {
                BufferedReader br;
                try {
                        URL url = new URL("http://www.google.com/ig/api?weather=北京");
                        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                        conn.setDoInput(true);
                        conn.connect();
                        br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                        OutputStreamWriter file_writer = new OutputStreamWriter(out);
                        String str = null;
                        while ((str = br.readLine()) != null) {
                                file_writer.write(str);
                        }
                        br.close();
                        file_writer.close();
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }结果conn.connect();这一句 抛出了 
java.net.UnknownHostException: Host is unresolved: www.google.com:80 
在AndroidManifest.xml中我也写了<uses-permission android:name="android.permission.INTERNET" /> 
希望知道的同学告诉我真相啊

解决方案 »

  1.   

    还是网络问题,你模拟器还是真机,先用下系统的浏览器,看能打开google不,然后测试你的程序。感觉网络不通
      

  2.   

    我在2.2中遇到同样问题  2。1中是好的 求解???why
      

  3.   

    楼主把URL地址改为:http://www.google.com.hk/ig/api?weather=北京
    试试,因为现在谷歌在中国的域名是www.google.com.hk
      

  4.   

    不能用中文,必须用城市的英文名称(即拼音)
    http://www.google.com/ig/api?weather=beijing
    http://www.google.com.hk/ig/api?weather=beijing
    两个都行。要想在模拟器上或真机上显示简体中文,需要用
    http://www.google.com/ig/api?hl=zh-cn&weather=Beijing
    并把解析得到的数据重新设置utf-8编码
      

  5.   

    关于显示简体中文,在我发的这个帖子里
    http://topic.csdn.net/u/20100821/14/9bdfdd31-e081-48e7-84d9-57672094afdc.html
      

  6.   

    这个鸟问题,真是蛋疼的不得了!自己架了个ejabberd服务,域名xxx,能ping通,telnet也可以。可在模拟器(2.2)上死活报上面的错误,如果把域名改成ip又可以了。不知道原因。楼主能否分享下!