2011-09-20 42 views
1

當我運行下面的代碼塊:接收java.net.MalformedURLException

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

任何人都可以指出我在做什麼錯?

+0

嘗試加載在PC瀏覽器的網址是什麼?它迴應? –

+0

代碼似乎對我來說,你確定這個異常來源於這裏嗎? – Caner

+0

該網址在瀏覽器中正常工作,但該例外僅源於此處。 – Harish

回答

-2

雖然使用此功能,你需要使用嘗試捕捉,因爲趕上MalformedURLException的

+0

是我保持代碼在嘗試catch塊 – Harish

-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 
} 
+0

燁我也做了同樣的不適用 – Harish

相關問題