tags:

views:

413

answers:

2

Just playing around with java trying to learn it etc.

Here is my code so far, using HtmlUnit.

package hsspider;

import com.gargoylesoftware.htmlunit.WebClient;

/**
 * @author 
 */
public class Main {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("starting ");
        Spider spider = new Spider();
        spider.Test();
    }
}


package hsspider;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
/**
 * @author 
 */
public class Spider {

    public void Test() throws Exception
    {
        final WebClient webClient = new WebClient();
        final HtmlPage page = webClient.getPage("http://www.google.com");
        System.out.println(page.getTitleText());
    }
}

I am using Netbeans.

I can't seem to figure out what the problem is, why doesn't it compile?

The error:

C:\Users\mrblah\.netbeans\6.8\var\cache\executor-snippets\run.xml:45: 
Cancelled by user.
BUILD FAILED (total time: 0 seconds)

The row in the xml is:

 <translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />
+5  A: 

Test is declared to throw Exception. If you add "throws Exception" to your main method it should compile. For example:

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws Exception {
    System.out.println("starting ");
    Spider spider = new Spider();
    spider.Test();
}
Steve B.
isn't throwing an Exception at the main method rather bad style? Why not just catch the Exception and print an error message?
NomeN
Sure it's bad style, but it.s certainly sufficient for a quick example for someone who just wants to know why their code isn't working.
Steve B.
+1  A: 

What Steve said is correct. But maybe there are some problems with the uppercase character of Test. A method always starts with a lower case character. So test would be better.

Martijn Courteaux
A method always starts with a lower case letter *by convention*. It is not required. Some conventions, for example, have private methods starting with an underscore.
Dave Jarvis