URLClassLoader

B

ballpointpenthief

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!
}
}
}
 
T

Thomas Hawtin

ballpointpenthief said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top