When I run the following block of code:
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();
}
I receive this error:
Exc = java.net.MalformedURLException
Can anyone point out what I'm doing wrong?
Your code should look like this:
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
}
While using this function you need to use try catch, in that catch the MalformedURLException
精彩评论