Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    Default Declaring URL object

    Hi all,

    when i write this line of code:

    Java Code:
    URL gamelan = new URL(Valid URL here);
    I had this exception : java.net.malformedurlexception

    so what's wrong with this line?:confused:

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    6

    Default

    What valid url do you insert, seems to me it snot valid at all

  3. #3
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    Default

    of course it is valid but i can't write any links in my posts as i'm new member:(
    i already wrote a valid url but i had the same error. so what's wrong with this line?

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    6

    Default

    You need valid links like:
    http://www.hostname/

  5. #5
    vogella is offline Member
    Join Date
    Aug 2009
    Location
    Heidelberg
    Posts
    47
    Rep Power
    0

    Default

    Can you please post the URL you are using?

  6. #6
    vogella is offline Member
    Join Date
    Aug 2009
    Location
    Heidelberg
    Posts
    47
    Rep Power
    0

    Default

    Here you find a working example for reading a HTML page via Java. It includes the definition of a valid URL: Reading HTML web pages with Java - Tutorial

  7. #7
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Catch the exception and have a look at what java doesn't like about your url.
    Java Code:
    String urlStr = "...";
    URL url = null;
    try {
        url = new URL(urlStr);
    } catch(MalformedURLException e) {
        System.out.println("MUE: " + e.getMessage());
        System.out.println("urlStr = " + urlStr);
    }
    System.out.println("url = " + url);

Similar Threads

  1. Declaring variables
    By Flashmatix in forum New To Java
    Replies: 12
    Last Post: 01-20-2009, 03:43 PM
  2. Declaring a Queue
    By rhm54 in forum New To Java
    Replies: 1
    Last Post: 03-21-2008, 05:02 AM
  3. Declaring Vector
    By mew in forum New To Java
    Replies: 1
    Last Post: 12-05-2007, 08:14 PM
  4. Declaring Interface
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-08-2007, 08:41 AM
  5. Declaring Enumeration
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-04-2007, 05:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •