我開着自己律瘋了這個.. 我追趕的調用Java程序,我寫的時候,在Eclipse命令行inputed參數的個數我得到正確的輸出,但在win cmd中,我得到了ArrayIndexOutOfBoundException。 然後我用的try-catch,再次,它工作在食,但不是在贏CMD ......我失去了什麼?正確的try-catch輸出食,但不是在cmd中
,如果我插入所有的觀點完美的作品從兩端,它只是當我想缺少的論點,這是行不通的。
下面我所使用的代碼的簡化版本:
public static PrintWriter outWrite;
public static String[] allInput;
public static void main(String [] args) {
// I first tried this
if(args.length==0){
System.out.println("Missing arguments. Please try again");
System.exit(0);
}
if (args.length==1){
System.out.println("Missing second argument. Please try again");
System.exit(0);
}
// and then the try-catch, I leave both of them here so you can see them
try{
myMethod(args[0]);
String input2 = args[1];
// here I'm just saving the output of myMethod to the input2
try {
outWrite = new PrintWriter(input2, "UTF-8");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ArrayIndexOutOfBoundsException e){
System.out.println("Missing arguments. Please try again");
System.exit(0);
}
}
我搜索這太Eclipse gives different output than cmd using runtime exec沒有成功
--- EDIT添加命令行中使用和精確的誤差:---- 在獲勝的命令行是java Driver
這應該給我留言我在寫代碼,而不是 它給了我下面的:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at myPackage.Driver.main(Driver.java:31)
line 31
在誤差對應於在上面的代碼段中的main()
方法內的第一行。
在Eclipse中(Driver.java:31)
有另一個號碼的正確指向myMethod(args[0])
線
正確的命令行是java myPackage.Driver fileIn.txt fileOut.txt
從雙贏CMD和eclipse
任何幫助將是真棒完美的作品! 謝謝:)
笏是你的Windows CMD用來調用你的應用程序的命令?你在Eclipse中設置的命令行參數是什麼?查看拋出異常的堆棧跟蹤也很有幫助。 – Hoopje 2014-12-03 17:39:19
@Hoopje - 感謝您的答覆,我通過添加命令行和錯誤編輯的主貼,希望這有助於! – TriRook 2014-12-03 17:52:41