🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8582

problem with NumberFormatException

#8582
From: KKenn10658
Date: Sat, 17 Mar 2001 02:57
44 lines
2218 bytes
I am having a problem with this bit of code. I enter only numbers into the
JTextFields. I am using try and catch blocks. Everytime I run the program and
use this method, I keep getting the NumberFormatException being caught.

I have studied the code and I do not see why I am getting the errror. Maybe a
fresh pair of eyes can spot a problem.

Thanks, Kevin

 private void UpdatePressed()
  {
   DecimalFormat payFormat = new DecimalFormat("$,##0.00");

  // data obtained from text fields

  int number = Integer.parseInt(tnumber.getText());
  int dateM = Integer.parseInt(tdateM.getText());
  int dateD = Integer.parseInt(tdateD.getText());
  int dateY = Integer.parseInt(tdateY.getText());
  int description = Integer.parseInt(tdescription.getText());
  int code = Integer.parseInt(tcode.getText());

    try
  {
 // data converted to numbers

    double pay = Double.parseDouble(tpay.getText());
    double fee = Double.parseDouble(tfee.getText());
    double credit = Double.parseDouble(tcredit.getText());
    double balance = Double.parseDouble(tbalance.getText());

  // calculate new balance and display with setText

    tbalance.setText(payFormat.format(((balance - pay) - fee) + credit));
    }// end try block

   // enter catch block
    catch (NumberFormatException nfe)
    {
    JOptionPane.showMessageDialog(null,"You must enter integers",
    "Invalid Number Format", JOptionPane.ERROR_MESSAGE);
    } // end catch block

 }
Technical Details
Message-ID: <20010316215736.05093.00000590@ng-mm1.aol.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!bignews.mediaways.net!news-fra1.dfn.de!news-lei1.dfn.de!news-was.dfn.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.skycache.com!Cidera!portc01.blue.aol.com!audrey04.news.aol.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,a85ee3fcb2e63654,start
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-16 19:02:42 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!bignews.mediaways.net!news-fra1.dfn.de!news-lei1.dfn.de!news-was.dfn.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.skycache.com!Cidera!portc01.blue.aol.com!audrey04.news.aol.com!not-for-mail
Lines: 44
X-Admin: news@aol.com
From: kkenn10658@aol.com (KKenn10658)
Newsgroups: borland.public.jbuilder.java.language
Date: 17 Mar 2001 02:57:36 GMT
Organization: AOL http://www.aol.com
Subject: problem with NumberFormatException
Message-ID: <20010316215736.05093.00000590@ng-mm1.aol.com>