在使用IDEA编写Java程序时,已经写好了程序没有报错,现在尝试往main方法传递参数,按照CSDN上的教程,点击上方菜单栏“运行”-“编辑配置”打开的结果是这样:
但是在CSDN上搜到的教程应该显示的结果不是这样:
可能是创建项目的时候就有问题。
主程序代码如下:
public class MainWindow {
private static void help(){
System.out.println("imageViewer work_dir image_format");
System.exit(1);//exit the program结束程序
}
public static void main(String[] args) {
//Parse the input arguments.
//如果参数个数不是2个,则通过调用help方法打印一条错误信息并退出程序。
if (args.length !=2){
System.out.println("Please specify REQUIRED arguments!");
help();
}
//通过args数组获取输入参数.
String work_dir = args[0];
String image_format = args[1];
//Show the image viewer.传入工作路径及图片格式
ImageViewer viewer = new ImageViewer(work_dir,image_format);
viewer.setTitle("ImageViewer");//设置标题
}
}
运行结果是这样:
你那个教程应该是老版本的页面,能跑起来idea就没设错,应该是你代码的问题。没了解过给main传参数怎么弄,你这个看着就像没获取到,你弄了控制台输出也放出来看看程序是怎么走的吧
修改选项 点击看看