所以我在我的代码中尝试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 link!
答案 0 :(得分:7)
当异常的堆栈跟踪显示时,上面的代码不会抛出异常,而是通过类actionPerformed()
的{{1}}方法抛出异常,该方法在某处调用f2_account_chief.TF2_Account_Chief
。 / p>