接收java.net.MalformedURLException

时间:2011-09-20 06:59:50

标签: android exception

当我运行以下代码块时:

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

有谁可以指出我做错了什么?

2 个答案:

答案 0 :(得分:-1)

您的代码应如下所示:

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
}

答案 1 :(得分:-2)

使用此函数时,您需要使用try catch,以捕获MalformedURLException

相关问题