Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
简单Java应用程序中的错误_Java_Htmlunit - Fatal编程技术网

简单Java应用程序中的错误

简单Java应用程序中的错误,java,htmlunit,Java,Htmlunit,只是在玩java,试图学习它等等 这是我到目前为止使用HtmlUnit编写的代码 package hsspider; import com.gargoylesoftware.htmlunit.WebClient; /** * @author */ public class Main { /** * @param args the command line arguments */ public static void main(String[] ar

只是在玩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" />

测试被声明为引发异常。如果将“throwsexception”添加到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
的大写字符可能存在一些问题。方法总是以小写字符开头。因此,
test
会更好。

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

按照惯例,方法总是以小写字母开头。这不是必需的。例如,有些约定有以下划线开头的私有方法。在主方法上抛出异常不是很糟糕吗?为什么不捕获异常并打印一条错误消息呢?当然,这是一种糟糕的风格,但对于那些只想知道自己的代码为什么不工作的人来说,这当然足以作为一个简单的例子。