I am defining a url in processing (or java) with the line:
URL base = new URL("http://www.google.com/");
So I get the following error: Default constructor cannot handle exception type MalformedURLException thrown by implicit super constructor. Must define an explicit constructor. Which I assume is because if my url isn't valid, there's no corresponding catch to catch the error (because I'm declaring my url outside of try).
But, i want to define this url outside of try, because my main try block is in a loop and the url is static. So there's no need to do the definition of the url more than once (and because it's static i'm not afraid of any MalformedURLExceptions).
How do I do that? Is there really no other way than to define the url within a separate try block? (because that seems a bit too much for just a simple static url)
// import libraries
import java.net.*;
import java.io.*;
// url
URL base = new URL("http://www.google.com");
void setup() {
}
void draw() {
try {
// retrieve url
String[] results = loadStrings(base);
// print results
println(results[0]);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (ConnectException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
// stop looping
noLoop();
}