我创建了一个为我做一些文件解析的类。我使得可以作为独立应用程序启动,从命令行获取文件名。 现在,我创建了另一个类,需要好好利用一下第一类是干什么的,我试图调用它像这样的主要方法:className.main(new String [] {“filename.txt”})?
className.main(new String[]{"filename.txt"});
然而,似乎事情并没有这样做精,因为我得到了一些空指针异常。当我插入system.out.println(args[0])
以查看发生了什么时,我得到了对资源的引用,而不是我期望的字符串。
这里是更多的代码:
// this is from the class that is reffered as 'new one'
// Cal the maze solver now for out.txt
String[] outFile = new String[]{"out.txt"};
MazeSolver.main(outFile);
// this is part of the MazeSolver main method
public static void main(String[] args) {
if(args.length != 1) {
System.out.println("Usage: java MazeSolver ");
System.exit(0);
}
// this is the part where i tried to debug
System.out.println(args.toString());
// and this is the error message that i got in terminal
// [Ljava.lang.String;@63b9240e <---------------------------------------
//ROWCOUNT: 199
//Exception in thread "main" java.lang.NullPointerException
我是否需要再创建一个方法,做同样的事情,但有不同的名称?
谢谢
Show yo你的代码,并解释你对'资源的引用'的含义。 – 2010-10-26 19:19:48
并显示例外... – extraneon 2010-10-26 19:23:10
如果我们有一些代码,我们可以看看它。但是你在那里应该有效。 – 2010-10-26 19:24:25