URLClassLoader

Discussion in 'Java' started by ballpointpenthief, Dec 19, 2006.

  1. I need to understand ClassLoader s for something, so I am starting with
    URLClassLoader to get started. I've fallen down before the first hurdle
    unfortunately.
    It might be a problem with the URL. I've not touched these before.

    If someone could find the problem in this code that would be great.
    Matt

    import java.net.URLClassLoader;
    import java.net.URL;
    import java.net.MalformedURLException;

    public class Test {

    public static void main(String argv[]) {

    URL[] urls = new URL[1];
    try {
    urls[0] = new URL("file:\\");

    } catch (MalformedURLException ex) {
    System.err.println(ex.getMessage());
    }
    URLClassLoader c = new URLClassLoader(urls);
    try {
    c.loadClass("House"); // There exists a House.class file in
    the working directory
    } catch (ClassNotFoundException ex) {
    System.err.println(ex.getMessage()); // I get to here, but
    I don't want to!
    }
    }
    }
     
    ballpointpenthief, Dec 19, 2006
    #1
    1. Advertising

  2. ballpointpenthief wrote:
    > urls[0] = new URL("file:\\");


    > } catch (ClassNotFoundException ex) {
    > System.err.println(ex.getMessage()); // I get to here, but
    > I don't want to!


    "file:\\" is not a correctly formed file URL. When I change it to
    "file:///", it works for me.

    Tom Hawtin
     
    Thomas Hawtin, Dec 19, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. netpro2k
    Replies:
    2
    Views:
    1,081
    netpro2k
    Aug 21, 2003
  2. Cory
    Replies:
    13
    Views:
    5,701
    swick
    May 31, 2011
  3. Sundar

    help.! Java URLClassloader

    Sundar, Nov 3, 2003, in forum: Java
    Replies:
    1
    Views:
    4,283
    Anton Spaans
    Nov 4, 2003
  4. Timothy Fosdike

    URLClassLoader slow in 1.4.2

    Timothy Fosdike, Aug 26, 2004, in forum: Java
    Replies:
    0
    Views:
    520
    Timothy Fosdike
    Aug 26, 2004
  5. Romain

    URLClassLoader and Tomcat

    Romain, Sep 28, 2005, in forum: Java
    Replies:
    2
    Views:
    4,457
    pkriens
    Sep 29, 2005
Loading...

Share This Page