开发者

Receiving java.net.MalformedURLException

开发者 https://www.devze.com 2023-04-06 14:50 出处:网络
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=EA3JQ0RZJT4e66223143

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

0

精彩评论

暂无评论...
验证码 换一张
取 消