1

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 checked 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.....

Siva K
  • 4,968
  • 14
  • 82
  • 161

2 Answers2

1

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);
aromero
  • 25,681
  • 6
  • 57
  • 79
1

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://..................");
ccheneson
  • 49,072
  • 8
  • 63
  • 68