【发布时间】:2014-02-16 05:03:34
【问题描述】:
对于我的程序,如果用户没有输入命令行参数并显示错误消息,我会在创建错误检查时遇到问题。而不是崩溃。 没有文本文件参数,我得到一个 ArrayIndexOutOfBoundsException :o ?
public static void main(String[] commandlineArgument) {
Integer[] array = ReadFile7.readFileReturnIntegers(commandlineArgument[0]);
ReadFile7.printArrayAndIntegerCount(array, commandlineArgument[0]);
if(commandlineArgument.length == 0){
System.out.println("Please file name " +
"as the first commandline argument.");
}
}
【问题讨论】:
-
只需将 'if(commandlineArgument.length == 0){...' 块移动到 main 方法的顶部。并添加'return 1;'在 if 块内停止执行
标签: java arrays error-handling command-line-arguments