title: Issues creating try-catch with switch statement
body: <p>I am fairly new in JAVA, learning it through my computer science course in high school and I am running into an issue with my try-catch block and switch statement.</p>
  
  <p>What I am doing is creating a conversion program where you put a number in a text field from 1 - 8, based on which switch statement I want executed (ie, 1 = centimeters to inches) and then you enter a value to be converted in another text field (ie, 12).</p>
  
  <p>The issue I'm running into is that I'm trying to place the switch statement inside a try-catch block that outputs an error if a non-number was put into the text fields and attempt to be run. </p>
  
  <pre><code>private void buttonConvertActionPerformed(java.awt.event.ActionEvent evt) {                                              
      //gathering inputs, declaring output
      double output;
      int choice = Integer.parseInt(txtfConversion.getText());
      double value = Double.parseDouble(txtfToBeConverted.getText());
  
      //decimal format for that long decimal numbers will not appear
      DecimalFormat df = new DecimalFormat("0.00");
  
      //setting output based on choice
      try{
          switch(choice){
             case 1: 
             output = value*2.52;
              labelOutput.setText(value+" inches = "+df.format(output)+" centimetres");
              break;
          case 2:
              output = value*30;
              labelOutput.setText(value+" feet = "+df.format(output)+" centimetres");
              break;
          case 3:
              output = value*0.91;
              labelOutput.setText(value+" yards = "+df.format(output)+" metres");
              break;
          case 4:
              output = value*1.6;
              labelOutput.setText(value+" miles = "+df.format(output)+" kilometres");
              break;
          case 5:
              output = value/2.52;
              labelOutput.setText(value+" centimetres = "+df.format(output)+" inches");
              break;
          case 6:
              output = value/30;
              labelOutput.setText(value+" centimetres = "+df.format(output)+" feet");
              break;
          case 7:
              output = value/0.91;
              labelOutput.setText(value+" metres = "+df.format(output)+" yards");
              break;
          case 8:
              output = value/1.6;
              labelOutput.setText(value+" kilometres = "+df.format(output)+" miles");
              break;
          default:
              labelOutput.setText("ERROR. Enter a version value!choice and a con");
              break;
          }
      }catch(NumberFormatException e){
       javax.swing.JOptionPane.showMessageDialog(null, "Please enter a numerical value!", "ERROR", javax.swing.JOptionPane.ERROR_MESSAGE);
      } 
  }
  </code></pre>
  
  <p>This is the error I receive:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "1q"
  at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
  at java.lang.Integer.parseInt(Integer.java:580)
  at java.lang.Integer.parseInt(Integer.java:615)
  at convertme.ConvertMe.buttonConvertActionPerformed(ConvertMe.java:199)
  at convertme.ConvertMe.access$000(ConvertMe.java:14)
  at convertme.ConvertMe$1.actionPerformed(ConvertMe.java:68)
  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
  at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
  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:6525)
  at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
  at java.awt.Component.processEvent(Component.java:6290)
  at java.awt.Container.processEvent(Container.java:2234)
  at java.awt.Component.dispatchEventImpl(Component.java:4881)
  at java.awt.Container.dispatchEventImpl(Container.java:2292)
  at java.awt.Component.dispatchEvent(Component.java:4703)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
  at java.awt.Container.dispatchEventImpl(Container.java:2278)
  at java.awt.Window.dispatchEventImpl(Window.java:2739)
  at java.awt.Component.dispatchEvent(Component.java:4703)
  at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
  at java.awt.EventQueue.access$400(EventQueue.java:97)
  at java.awt.EventQueue$3.run(EventQueue.java:697)
  at java.awt.EventQueue$3.run(EventQueue.java:691)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
  at java.awt.EventQueue$4.run(EventQueue.java:719)
  at java.awt.EventQueue$4.run(EventQueue.java:717)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
  </code></pre>