开发者

cant get xml file from an URL in android

开发者 https://www.devze.com 2023-03-02 11:13 出处:网络
in my app i am trying to get an xml file from an URL. the url to which trying get consists of a string. Following is part of my code

in my app i am trying to get an xml file from an URL. the url to which trying get consists of a string. Following is part of my code

  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());
       }            
  }

When i c开发者_如何学运维hecked with log value in log cat it shows that it is getting in to the URL and then into the getWebPageContents(url)

in the getWebPageContents(URL url) it is getting into the first try block and not in the second try block

Where i am going wrong please help me.....


You are not setting the url you want to get anywhere so I believe rsp.getEntity() results in a NullPointerException

Also HttpGet accepts a URI or String so either you use it as:

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

or change

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

to

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


You are not using the URL in your code:

HttpGet get = new HttpGet();

I think this is what you want:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号