And some times i'm getting java.net.MalFormedURLException what's the reason behind this and how can i resolve this..
My code is as follows..
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://w3devadv.liveproj.com /api/apiRequest.php?Method=getdealdetails&DealId=2&SessionId=EA3JQ0RZJT4e66223143fc5");
/**
* Create handler to handle XML Tags (extends DefaultHandler)
*/
DealsHandler myXMLHandler = new DealsHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
In handler i'm writing the following code in startelement
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
currentElement = true;
if (localName.equalsIgnoreCase("data")) {
dealsdata = new DealsData();
} else if (localName.equalsIgnoreCase("dealdetails")) {
deals = new Deals();
} else if (localName.equalsIgnoreCase("title")) {
deals.title = attributes.getLocalName(0);
}
i'm getting the above said exception how can i resolve this.
0
A
回答
2
您收到此錯誤支持,因爲.....
"This exception is thrown when a program attempts to create an URL from an
incorrect specification."
0
"http://w3devadv.liveproj.com /api/apiRequest.php?Method=getdealdetails&DealId=2&SessionId=EA3JQ0RZJT4e66223143fc5"
這可能是由於URL中的空間。
1
傳遞字符串URL 才能將字符串到標準的URL格式
這樣..
String url = new String(str.trim().replace(" ", "%20").replace("&", "%26")
.replace(",", "%2c").replace("(", "%28").replace(")", "%29")
.replace("!", "%21").replace("=", "%3D").replace("<", "%3C")
.replace(">", "%3E").replace("#", "%23").replace("$", "%24")
.replace("'", "%27").replace("*", "%2A").replace("-", "%2D")
.replace(".", "%2E").replace("/", "%2F").replace(":", "%3A")
.replace(";", "%3B").replace("?", "%3F").replace("@", "%40")
.replace("[", "%5B").replace("\\", "%5C").replace("]", "%5D")
.replace("_", "%5F").replace("`", "%60").replace("{", "%7B")
.replace("|", "%7C").replace("}", "%7D"));
您可以使用此功能,方便您隨時隨地獲取URL,並用它,所以你可以克服這個錯誤並讓你的字符串工作。
我知道你接受了答案,但這也可以幫助其他人也我認爲 謝謝你。
相關問題
- 1. java.net.SocketException異常:地址族不受協議
- 2. 請求時間失敗:java.net.socketexception:協議不支持的地址族
- 3. DEBUG/SntpClient(70):請求時間失敗:java.net.SocketException異常:地址家族不受協議在Android
- 4. java.net.SocketException異常:地址家族不受協議支持
- 5. java.net.SocketException異常:地址家族不受協議在Android模擬器
- 6. DEBUG/SntpClient(60):請求時間失敗:java.net.SocketException:協議不支持的地址系列
- 7. DEBUG/SntpClient(61):請求時間失敗:java.net.SocketException:協議不支持的地址系列
- 8. java.net.SocketException:協議問題不支持的地址家族
- 9. recvfrom的:錯誤地址,SENDTO:地址家族不受協議
- 10. 家庭地址協議族不
- 11. ffserver的:綁定(端口8090):地址家族不受協議
- 12. EPMD錯誤打開流套接字:地址家族不受協議
- 13. 搖籃項目刷新失敗 - 協議家族不可用
- 14. 綁定:協議地址族不支持
- 15. 協議不支持地址族? sendto
- 16. 家庭地址協議族不支持 - 特定計算機
- 17. java.net.scoket異常地址不是由協議
- 18. Jesey客戶:協議家族的IPv6地址
- 19. 的Android HTTPS請求,SSL協議失敗
- 20. WCF:協議例外 - 400錯誤請求
- 21. 不支持地址族異常重現
- 22. 失敗的地方例外:java.net.SocketException異常:沒有可用的緩衝空間(最大連接數達到?):
- 23. 外部協議請求
- 24. 網絡編程:Socket函數:地址族VS協議族
- 25. 的Android java.net.SocketException異常:socket失敗
- 26. 套接字直接協議錯誤:「協議地址族不支持」
- 27. Errno :: EAFNOSUPPORT(地址族不支持協議 - 套接字(2)):
- 28. 協議UDP不支持的地址族 - C
- 29. SocketException:與請求協議不兼容的地址
- 30. MySQL/VB.NET - 使用與請求的協議不兼容的地址