对于我的程序,如果用户没有输入命令行参数并显示错误消息,那么我在创建错误检查时遇到问题。而不是崩溃。 没有文本文件参数,我得到一个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.");
}
}
只需推动 '如果(commandlineArgument.length == 0){...' 块到主要方法的顶部。并添加'返回1;'里面如果阻止执行 –