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

2 Answers 2

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://..................");
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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.