kno*_*erg 0 java swing exception-handling try-catch numberformatexception
所以我想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();
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误:
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)
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?有任何想法吗?
更新:这是完整代码的PasteBin链接!
正如异常的堆栈跟踪所示,异常不是由上面的代码抛出的,而是由actionPerformed()类的方法抛出f2_account_chief.TF2_Account_Chief,它调用Integer.parseInt()某个地方.
| 归档时间: |
|
| 查看次数: |
1108 次 |
| 最近记录: |