0

所以我试图catch (NumberFormatException ex)在我的代码中:

private void Processes() throws IOException, InterruptedException {
    // New Thread "processesThread" will start here.
    final Object mon = threadBlock;
    Thread processesThread = new Thread(new Runnable() {
        @Override
        public void run() {
            synchronized (mon) {
                try {
                    try {
                        try {
                            Runtime rt = Runtime.getRuntime();
                            // "runnableTogether" will be the number that the user inputs in the GUI.
                            switch (runnableTogether) {
                                case 4:
                                processes.add(rt.exec("C:/Windows/System32/SoundRecorder.exe"));
                                case 3:
                                processes.add(rt.exec("C:/Windows/System32/taskmgr.exe"));
                                case 2:
                                processes.add(rt.exec("C:/Windows/System32/notepad.exe"));
                                case 1:
                                processes.add(rt.exec("C:/Windows/System32/calc.exe"));
                                Thread.sleep(5000);
                                destroyProcesses(processes);
                                break;
                                default:
                                invalidInput();
                                break;
                            }
                            mon.wait();
                            } catch (IOException ex) {
                        }
                        } catch (InterruptedException ex) {
                    }
                    } catch (NumberFormatException ex) {
                    nullInput();
                }
            }
        }
    });

但它给了我这个错误:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:504)
        at java.lang.Integer.parseInt(Integer.java:527)
        at tf2_account_chief.TF2_Account_Chief.actionPerformed(TF2_Account_Chief.java:425)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
        at java.awt.Component.processMouseEvent(Component.java:6505)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)

我在这里做错了什么?有任何想法吗?

更新:这是完整代码的PasteBin 链接!

4

1 回答 1

7

正如异常的堆栈跟踪所示,异常不是由上面的代码引发的,而是由在某处调用actionPerformed()的类的方法引发的。f2_account_chief.TF2_Account_ChiefInteger.parseInt()

于 2013-07-05T11:54:29.847 回答