0

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" />

3 Answers 3

5

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();
}
Sign up to request clarification or add additional context in comments.

2 Comments

isn't throwing an Exception at the main method rather bad style? Why not just catch the Exception and print an error message?
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.
1

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.

1 Comment

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.
1

Unchecking the "Compile on Save" option of the "Properties" tab in Netbeans 7.1.2 resolved a similar error message for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.