简单 Java 应用程序中的错误

发布于 2024-08-16 21:00:32 字数 1159 浏览 9 评论 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" />

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

巾帼英雄 2024-08-23 21:00:32

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

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

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();
}
岁月无声 2024-08-23 21:00:32

史蒂夫说的是正确的。但Test的大写字符可能存在一些问题。方法始终以小写字符开头。所以 test 会更好。

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.

掀纱窥君容 2024-08-23 21:00:32

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文