0

只是在玩 java 试图学习它等。

到目前为止,这是我的代码,使用 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());
    }
}

我正在使用 Netbeans。

我似乎无法弄清楚问题是什么,为什么它不编译?

错误:

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

xml中的行是:

 <translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />
4

3 回答 3

5

测试被声明抛出异常。如果您将“抛出异常”添加到您的主要方法中,它应该可以编译。例如:

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws Exception {
    System.out.println("starting ");
    Spider spider = new Spider();
    spider.Test();
}
于 2010-01-05T18:44:00.210 回答
1

取消选中 Netbeans 7.1.2 中“属性”选项卡的“保存时编译”选项为我解决了类似的错误消息。

于 2012-07-04T20:54:12.687 回答
1

史蒂夫说的是对的。但也许 . 的大写字符存在一些问题Test。方法总是以小写字符开头。所以test会更好。

于 2010-01-05T19:05:16.213 回答