不能从一个机器人拿到URL xml文件 [英] cant get xml file from an URL in android

查看:217
本文介绍了不能从一个机器人拿到URL xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我试图获得来自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

还有<一个href=\"http://developer.android.com/reference/org/apache/http/client/methods/HttpGet.html#HttpGet%28java.net.URI%29\"相对=nofollow> 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://..................");

这篇关于不能从一个机器人拿到URL xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆