tags:

views:

79

answers:

1

Hello, I'm trying to execute this code from the HTMLUnit tutorial:

final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");

but I get the MalformedURLException in the second line when saving it in Eclipse (if I compile and run the code, I get it too). What's the problem? TIA

PS: I'm new to Java

Up:

Here's the stack trace:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/auth/CredentialsProvider
    at Tester.main(Tester.java:12)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.auth.CredentialsProvider
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 1 more
A: 

I tried this in Eclipse 3.5 and it is working correctly, and the test is passing. I assume that you have included the necessary HTMLUnit JARs into your project? I took all the JARs from the HTMLUnit lib directory and added them to the build path of my project.

Also, can you catch the exception and post the stack trace here?

try {
  final WebClient webClient = new WebClient();
  final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
  assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText());
}
catch (Exception e) {
  e.printStackTrace();
}
Kaleb Brasee