我創建了一個爲我做一些文件解析的類。我使得可以作爲獨立應用程序啓動,從命令行獲取文件名。 現在,我創建了另一個類,需要好好利用一下第一類是幹什麼的,我試圖調用它像這樣的主要方法: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