3 Replies Latest reply: Nov 26, 2012 2:32 PM by 896976 RSS

    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException:

    896976
      Hi I am new to Java and I am having problems with this code:

      here is the error
      Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "3 "
           at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
           at java.lang.Integer.parseInt(Integer.java:492)
           at java.lang.Integer.parseInt(Integer.java:527)
           at NewJFrame.jButton_CalculateActionPerformed(NewJFrame.java:161)
           at NewJFrame.access$100(NewJFrame.java:10)
           at NewJFrame$2.actionPerformed(NewJFrame.java:61)
       
        private void jButton_CalculateActionPerformed(java.awt.event.ActionEvent evt) {                                                  
              // TODO add your handling code here:
                int numTables = Integer.parseInt(jTextField_NumberOfTables.getText());
              int numCalc = Integer.parseInt(jTextField_NumberOfCalculations.getText());
              String operator = jComboBox_Operation.getSelectedItem().toString();
              
              String table = ""; 
              
              if (operator.equalsIgnoreCase("powers")) {
                     table = CalculateTables.powersTable(numTables, numCalc);
                     jLabel_TableType.setText("powers");
              }
      public class CalculateTables {
          
        public static String
                 powersTable(int numTables, int numCalc) {
                 
                 //fill temArray with powers using nested for statements
                 String output = "";
             for (int i =0; i <=  numTables; i++) {
                output += i + " Tables\r\n";      
                      for (int j =0; j <= numCalc; j++) {
                          output += String.format("%s ^ %s = %.2f\r\n",i,j,Math.pow(i,j)); 
                      }
          output += "\r\n";
      }    
       return output;    
        }
      It seems to me anyway that the Integer.parseInt(jTextField_NumberOfTables.getText());
      is not working
      this piece of code, I an getting text from the user and I need to onverted to an integer
       
       int numTables = Integer.parseInt(jTextField_NumberOfTables.getText());
              int numCalc = Integer.parseInt(jTextField_NumberOfCalculations.getText());