当我运行以下代码块时:
try {
URL surl = new URL("http://w3devadv.liveproj.com/api/apiRequest.php?Method=getdealdetails&DealId=2&SessionId=EA3JQ0RZJT4e66223143fc5");
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp1 = spf.newSAXParser();
XMLReader xr = sp1.getXMLReader();
DealdetailsHandler dh = new DealdetailsHandler();
xr.setContentHandler(dh);
xr.parse(new InputSource(surl.openStream()));
} catch (MalformedURLException mue) {
mue.printstacktrace();
}我收到这个错误:
Exc = java.net.MalformedURLException
有人能指出我做错了什么吗?
发布于 2011-09-20 07:20:20
您的代码应该如下所示:
try {
URL surl = new URL(
"http://w3devadv.liveproj.com/api/apiRequest.php?Method=getdealdetails&DealId=2&SessionId=EA3JQ0RZJT4e66223143fc5");
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp1 = spf.newSAXParser();
XMLReader xr = sp1.getXMLReader();
DealdetailsHandler dh = new DealdetailsHandler();
xr.setContentHandler(dh);
xr.parse(new InputSource(surl.openStream()));
} catch (MalformedURLException e) {
// Handled the exception in an appropriate way
}发布于 2011-09-20 07:08:17
在使用此函数时,您需要使用that,在该捕获中使用MalformedURLException
https://stackoverflow.com/questions/7481270
复制相似问题