Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By Norm

Thread: NumberFormatException: For input string:

  1. #1
    MS-POWER is offline Member
    Join Date
    Oct 2016
    Posts
    24
    Rep Power
    0

    Default NumberFormatException: For input string:

    Dear when I Insert data to database I received this error , the type in database is Double , this error is happened for Number 5 , any one can explain this to me please ...

    java.lang.NumberFormatException: For input string: "2280.0"




    العاب


    Java Code:
    private void jButtonFinishPrintingNOReceiptActionPerformed(java.awt.event.ActionEvent evt) {                                                               
    
          try {
    
                String sql = "insert into Payments_POS  (Invoice_Number,Date_Sold,Time_Sold,
    Payment_Type,Amount_Tendered,Paid_Amount,Amount_Still_Due,Change_Due,
    Comment)values(?,?,?,?,?,?,?,?,?)";
    
                pst = conn.prepareStatement(sql);
                
                pst.setInt(1,    (Integer)parseInt(FiledInVoiveNumber.getText()));
                pst.setString(2,  Field1Date.getText());
                pst.setString(3,  Field1Time.getText());
                pst.setString(4, (String) jComboBoxPaymentTypes.getSelectedItem());
                pst.setDouble(5, (Double)parseDouble(paymentFieldTotalInvoice.getText()));
                pst.setDouble(6, (Double)parseDouble(TotalTablePaymentFiled.getText()));
                pst.setDouble(7, (Double)parseDouble(AmountStillDue.getText()));
                pst.setDouble(8, (Double)parseDouble(ChangeDue.getText()));
                pst.setString(9, jTextAreaComments.getText());
                
    
                pst.execute();
                
                if(!jComboBoxPaymentTypes.getSelectedItem().equals("Loyalty"))
                loyaltyCalculation();
                else{
          
                 }
                
                
                
    
               En_PaymentChangeDue F = new En_PaymentChangeDue();
               En_PaymentChangeDue.ChangeDue2.setText(this.ChangeDue.getText());
               F.setVisible(true);     
             
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);
            } finally {
                try {
    
                    rs.close();
                    pst.close();
    
                } catch (Exception e) {
                }
            }
    
             
             
        dispose();
    
    د
    Last edited by MS-POWER; 11-09-2016 at 10:21 PM.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: NumberFormatException: For input string:

    What does the method parseDouble() look like?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    MS-POWER is offline Member
    Join Date
    Oct 2016
    Posts
    24
    Rep Power
    0

    Default Re: NumberFormatException: For input string:

    Quote Originally Posted by SurfMan View Post
    What does the method parseDouble() look like?
    ????


    it was :
    pst.setString(5, paymentFieldTotalInvoice.getText());

    then I tried to change it many time but I could not fix it.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: NumberFormatException: For input string:

    Here is the statement.
    Java Code:
    pst.setDouble(5, (Double)parseDouble(paymentFieldTotalInvoice.getText()));
    What does the method (the actual code) for parseDouble() look like? You call it thusly:
    Java Code:
    (Double)parseDouble(paymentFieldTotalInvoice.getText())
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: NumberFormatException: For input string:

    Do you have an import statement like this:
    Java Code:
    import static java.lang.Double.parseDouble; //<<<<<<<< allow call to parseDouble without Double.
    Can you copy the full text of the error message and paste it here? It should look like this:
    Java Code:
    Exception in thread "main" java.lang.NumberFormatException: For input string: "1.23"
    	at java.lang.NumberFormatException.forInputString(Unknown Source)
    	at java.lang.Integer.parseInt(Unknown Source)
    	at java.lang.Integer.parseInt(Unknown Source)
    	at TestCode22.main(TestCode22.java:1126)
    This stack trace shows the call is to parseInt for which "1.23" is invalid.
    Last edited by Norm; 11-09-2016 at 10:57 PM.
    SurfMan likes this.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    MS-POWER is offline Member
    Join Date
    Oct 2016
    Posts
    24
    Rep Power
    0

    Default Re: NumberFormatException: For input string:

    Quote Originally Posted by Norm View Post
    Do you have an import statement like this:
    Java Code:
    import static java.lang.Double.parseDouble; //<<<<<<<< allow call to parseDouble without Double.
    Can you copy the full text of the error message and paste it here? It should look like this:
    Java Code:
    Exception in thread "main" java.lang.NumberFormatException: For input string: "1.23"
    	at java.lang.NumberFormatException.forInputString(Unknown Source)
    	at java.lang.Integer.parseInt(Unknown Source)
    	at java.lang.Integer.parseInt(Unknown Source)
    	at TestCode22.main(TestCode22.java:1126)
    This stack trace shows the call is to parseInt for which "1.23" is invalid.


    thanks it solved , it was conflict Double and Integer

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: NumberFormatException: For input string:

    Quote Originally Posted by Norm View Post
    Do you have an import statement like this:
    Java Code:
    import static java.lang.Double.parseDouble; //<<<<<<<< allow call to parseDouble without Double.
    Good catch, the static import. I thought OP had rolled his own method. I hate static imports. It makes is so unclear where stuff comes from. You would acutally need to rely on proper syntax coloring to identify the origin of the method.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Replies: 1
    Last Post: 03-31-2013, 12:27 AM
  2. java.lang.NumberFormatException: For input string: ""
    By deshmukh.niraj04 in forum New To Java
    Replies: 16
    Last Post: 08-22-2011, 01:02 PM
  3. Replies: 14
    Last Post: 04-08-2011, 06:01 PM
  4. java.lang.NumberFormatException: For input string: ""
    By chathura992 in forum New To Java
    Replies: 3
    Last Post: 01-08-2011, 01:10 AM
  5. jsp insert into database error(java.lang.NumberFormatException: For input string: "")
    By cypher_girl in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-22-2009, 03:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •