Android开发-HttpClient异常
大家好,我正在 Eclipse 中开发 Android 应用程序,并遇到了一个奇怪的异常,我无法确定。异常发生在:
public int getEvents(){
NodeList property_nodes;
NodeList event_nodes;
InputStream is;
parserFactory = DocumentBuilderFactory.newInstance();
try{
parser = parserFactory.newDocumentBuilder();
//check the last updated date
get = new HttpGet("http://whatever.com/test_date.php");
response = client.execute(get);
entity = response.getEntity();
...
client.execute(get) 行。它被捕获了,
} catch (Exception e){
String e_cause = e.getMessage();
return -1;
}
e_cause 只是“whatever.com”,没有其他内容。这个确切的代码今天早些时候可以工作,但我不知道如何进一步诊断这个问题!有谁知道为什么异常会从 getMessage 函数返回 URL,或者获取有关错误来源的更多信息的方法?
非常感谢。
Hey everyone, I'm working on an Android App in Eclipse, and getting a wierd exception that I'm having trouble nailing down. The exception occurs in:
public int getEvents(){
NodeList property_nodes;
NodeList event_nodes;
InputStream is;
parserFactory = DocumentBuilderFactory.newInstance();
try{
parser = parserFactory.newDocumentBuilder();
//check the last updated date
get = new HttpGet("http://whatever.com/test_date.php");
response = client.execute(get);
entity = response.getEntity();
...
at the client.execute(get) line. It's caught by,
} catch (Exception e){
String e_cause = e.getMessage();
return -1;
}
and e_cause is just "whatever.com" and nothing else. This exact code was working earlier today, and I can't figure out how to diagnose this further! Does anyone know why the exception would return a URL from the getMessage function, or a way to get more information about the source of the error?
Thanks so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两个可能的原因。您需要在Manifest中设置访问互联网的权限。有这样做的许可。另一个原因是您所在的网络无法找到域名,因此请尝试 ping 地址以获取网站的 IP 地址,然后将其代替域名。因此,如果 www.somesite.com/abc 使用 ipaddress/abc 代替。那应该可以解决它。
two possible reasons. you need to set permission in Manifest to access the Internet. there is a permission for this. The other reason is the network you are on cannot find the domain name so trying pinging the address to get the ip address of the website and just put that in instead of the domain name. So if www.somesite.com/abc use ipaddress/abc instead. that should solve it.
谢谢大家的回复。问题是我的模拟器由于某种原因与我的网络断开了连接。我在做其他事情时将其打开了几个小时,然后再回来,却无法连接。我重新打开模拟器,一切正常。我可能应该先尝试一下......
Thanks for the responses everyone. The problem was that my emulator had disconnected from my network for some reason. I left it open for a couple hours while doing something else, then came back to it, and it wasn't connecting. I re-opened the emulator, and everything worked fine. I probably should have tried that first...