0

So I am trying to catch (NumberFormatException ex) in my code:

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(); } } } }); 

But it gives me this error:

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) 

What am I doing wrong here? Any ideas?

UPDATE: Here is the PasteBin link for the full code!

6
  • can you post the full stack trace. the reason of the exception can be better seen in the "caused by" clause. Commented Jul 5, 2013 at 11:56
  • @erencan That is the full stack trace. I am using NetBeans if that changes anything Commented Jul 5, 2013 at 11:57
  • what is there in the TF2_Account_Chief.java:425 ? Commented Jul 5, 2013 at 12:00
  • I will post a PasteBin link of the full code. Commented Jul 5, 2013 at 12:01
  • @erencan Ok. I added the PasteBin link. Commented Jul 5, 2013 at 12:05

1 Answer 1

7

As the stack trace of the exception shows, the exception is not thrown by the code above, but by the actionPerformed() method of the class f2_account_chief.TF2_Account_Chief, which calls Integer.parseInt() somewhere.

Sign up to request clarification or add additional context in comments.

5 Comments

Check the PasteBin link I added.
Why would I check it? Check my answer and read the stack trace instead. The exception is thrown at line 425, not by the above code.
This is what is at line 425: runnableTogether = Integer.parseInt(runnableTogetherInput.getText()); But what would I do to catch that?
You would enclose the lines 425 to 434 in a try block, catch NumberFormatException, and inside the cacth block, do whatever you want if the runnableTogetherInput.getText() is not a valid Integer.
@user2506658 Write the Integer.parseInt(runnableTogetherInput.getText()) one in a try/catch and then catch the ParseException.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.