![](/img/trans.png)
[英]Unhandled exception java.net.MalformedURLException in an Android app
[英]unhandled exception java.net.malformedurlexception
为什么这段代码在java中给我一个unhandled exception java.net.malformedurlexception
?
String u = "http://webapi.com/demo.zip";
URL url = new URL(u);
有人能告诉我如何解决?
你需要处理可能的异常。
试试这个:
try {
String u = "http://webapi.com/demo.zip";
URL url = new URL(u);
} catch (MalformedURLException e) {
e.printStackTrace();
}
使用try catch语句来处理异常:
String u = "http://webapi.com/demo.zip";
try {
URL url = new URL(u);
} catch (MalformedURLException e) {
//do whatever you want to do if you get the exception here
}
java.net.malformedurlexception
这意味着在规范字符串中找不到合法协议或者无法解析字符串或者您的URL未确认规范或缺少组件我认为这将有助于您理解URL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.