#Process finished with exit code -1 问题处理

2022-08-03,,,

Process finished with exit code -1 问题处理

在上图中运行代码时在无法输入的情况下,只能强制停止运行后出现
Process finished with exit code -1

我在百度上搜索了相关的问题,也未能解决,将程序代码拷贝到eclipse下能够正常运行,也能够正常输入字符。证明程序代码没有问题。

@Test
        public void testLogin() {
            Scanner scanner = new Scanner(System.in);

            System.out.print("用户名:");
            String user = scanner.nextLine();
            System.out.print("密码:");
            String password = scanner.nextLine();
            //SELECT user,password FROM user_table WHERE user = '1' or ' AND password = '=1 or '1' = '1'
            String sql = "SELECT user,password FROM user_table WHERE user = ? and password = ?";
            User returnUser = getInstance(User.class,sql,user,password);
            if(returnUser != null){
                System.out.println("登录成功");
            }else{
                System.out.println("用户名不存在或密码错误");
            }
        }

最后发现问题出在IDEA在Junit时不能从控制台输入问题

1. IDEA版本:2018
2. JDKB版本:1.8
4. Junit版本:4.5

在eclipse转IDEA,今天使用IDEA写一个单元测试的时候,发现@Test从控制台不能输入数据,这种情况我用eclipse是没出现过的,我也找到了好多博客,说是junit的版本与IDEA的不兼容,改成用main方法写就可以解决了,但是,我找到了另外一个大神的博客,只需要添加一个参数就可以解决。
参考博客地址:https://blog.csdn.net/u010999809/article/details/88733014

1.首先,打开IDEA安装根目录下的bin文件夹,找到idea.exe.vmoptionsidea64.exe.vmoptions这两个文件
2.对这两个文件进行编辑,在后面添加一段参数 -Deditable.java.test.console=true

3.重启IDEA,就可以在@Test下,使用Scanner从控制台输入了

本文地址:https://blog.csdn.net/shouji6175/article/details/107340922

《#Process finished with exit code -1 问题处理.doc》

下载本文的Word格式文档,以方便收藏与打印。