不能从一个机器人拿到URL xml文件机器人、文件、URL、xml

2023-09-07 09:20:53 作者:白天不懂爺旳黑

在我的应用我试图获得来自URL的XML文件。到试图获取URL包含一个字符串。以下是我的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());
       }            
  }

当我在日志日志猫值检查它表明它越来越到的URL,然后进入getWebPageContents(URL)

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)

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

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

推荐答案

您没有设置你想要得到任何地方,所以我相信,网址 rsp.getEntity()结果在一个NullPointerException异常

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

还有 HTTPGET 接受 URI 字符串所以要么你用它作为:

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

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

或更改

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

URI url = new URI("http://..................");
 
精彩推荐
图片推荐