How come this code is giving me a unhandled exception java.net.malformedurlexception
in java ?
String u = "http://webapi.com/demo.zip";
URL url = new URL(u);
Can someone tell me how to fix?
You need to handle the posible exception.
Try with this:
try {
String u = "http://webapi.com/demo.zip";
URL url = new URL(u);
} catch (MalformedURLException e) {
e.printStackTrace();
}
Use a try catch statement to handle exceptions:
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With