java - unreported exception MalformedURLException when creating a URL -


excuse me lack of java skills, c kind of person.. beginning android development , want make request. however, cannot simple url type compile correctly. keep getting error:

helloworld.java:17: error: unreported exception malformedurlexception; must caught or declared thrown  url url = new url("http://www.google.com/");  ^ 1 error 

when running simple code:

 import java.io.bufferedreader;  import java.io.ioexception;  import java.io.inputstream;  import java.io.inputstreamreader;  import java.io.outputstream;  import java.io.outputstreamwriter;  import java.io.reader;  import java.io.writer;  import java.net.httpurlconnection;  import java.net.protocolexception;  import java.net.url;  import java.net.urlconnection;  public class helloworld{       public static void main(string []args){         url url = new url("http://www.google.com/");          system.out.println(url.tostring());      } } 

what doing wrong here?

for checked exception, becomes mandatory handle them in code. here 2 ways that.

in general, can either pass on exception handling caller of declaring method using throws clause. or can handle them there using try-catch[-finally] construct.

in case, either need add throws clause main() method as

public static void main(string []args) throws malformedurlexception{

or need surround url declaration try-catch block, here:

try{     url url = new url("http://www.google.com/");     //more code goes here }catch(malformedurlexception ex){ //do exception handling here } 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -