我有一个类SpellingSuggestor
,它的构造函数签名调用带有文件的构造函数的参数
public SpellingSuggestor(File file) throws IOException { // something }
我想从另一个类中调用它的构造。该代码是这样的
public class NLPApplications
public static void main(String[] args) {
String w= "randomword";
URL url = getClass().getResource("big.txt");
File file = new File(url.getPath());
System.out.println((new SpellingSuggestor(file)).correct(w));
}
}
但在URL url..
线上面所示的错误说
- 网址无法解析为一个类型。
- 无法对Object类型的非静态方法getClass()进行静态引用。
怎么回事?
我看着这个问题How to pass a text file as a argument?。我不熟悉处理Java中的文件,所以这个问题。
即使如此,它也会提示“URL无法解析为某种类型”。 – OneMoreError 2013-04-29 05:43:32
编辑我的答案。 – NINCOMPOOP 2013-04-29 05:44:08
Yups ..明白了!谢谢 – OneMoreError 2013-04-29 05:45:34