Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从android中的URL获取xml文件_Android_Http_Url - Fatal编程技术网

无法从android中的URL获取xml文件

无法从android中的URL获取xml文件,android,http,url,Android,Http,Url,在我的应用程序中,我试图从URL获取xml文件。尝试获取所指向的url由字符串组成。下面是我代码的一部分 URL url = new URL("http://.................."); Log.e("Gallery URl",""+url); getWebPageContents(url); } private void getWebPageContents(URL url) { try{ if(url != null)

在我的应用程序中,我试图从URL获取xml文件。尝试获取所指向的url由字符串组成。下面是我代码的一部分

  URL url = new URL("http://..................");
  Log.e("Gallery URl",""+url);
  getWebPageContents(url);
  }

   private void getWebPageContents(URL url) 
   {
     try{
    if(url != null)
    Log.e("webpage",""+url);
    {
          HttpClient client = new DefaultHttpClient();
      HttpGet get = new HttpGet();
      try
         {
        HttpResponse rsp = client.execute(get);
        String tmpstr = EntityUtils.toString(rsp.getEntity()); 
        Log.e("UserData "+tmpstr);
        UserManual.IMGDATA=tmpstr;
        getUserRegisteredContents(tmpstr);
         }
    catch(Exception asd)
       {
         Log.e(asd.toString());
       }            
  }
当我在log cat中使用log值进行检查时,它显示它正在进入URL,然后进入getWebPageContents(URL)

在getWebPageContents(URL)中,它进入第一个try块,而不是第二个try块


哪里出了问题,请帮助我….

您的代码中没有使用URL:

HttpGet get = new HttpGet();
我想这就是你想要的:

URI uri = new URI("http://..................");
HttpGet get = new HttpGet(uri);

您没有设置要到达任何地方的url,因此我相信
rsp.getEntity()
会导致NullPointerException

还接受
URI
字符串
,因此您可以将其用作:

HttpGet get = new HttpGet("http://www.example.com");
或改变

URL url = new URL("http://..................");

URI url = new URI("http://..................");