8 Replies Latest reply: Oct 20, 2006 1:17 PM by 807607 RSS

    NumberFormatException plz help...

    807607
      Can some one please provide me code snippet to reproduce following exception.Line no's does not matter but stack trace should be same.

      java.lang.NumberFormatException:
      at java.lang.Long.parseLong(Long.java:331)
      at java.lang.Long.parseLong(Long.java:363)
      at java.text.DigitList.getLong(DigitList.java:153)
      at java.text.DecimalFormat.parse(DecimalFormat.java:808)
      at java.text.SimpleDateFormat.subparse(SimpleDateFormat.java:987)
      at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:708)
      ...


      Thanks,
      kanth
        • 1. Re: NumberFormatException plz help...
          800323
          Don't you have the source?
          If not, could you decompile the byte-code?
          • 2. Re: NumberFormatException plz help...
            807607
            I have the source code.But this exception is not reproducable in my application.Also I did not knowhow to reproduce it.Based on the Run time attribute this exception triggered.
            • 3. Re: NumberFormatException plz help...
              800323
              Doesn't the exception give you the line number of the source? I ask because it will show which parse() method is being called.
              • 4. Re: NumberFormatException plz help...
                807607
                I do not have the line no.Because JIt are used and it is already compiled code.
                • 5. Re: NumberFormatException plz help...
                  807607
                  I have the source code.
                  I do not have the line no.Because JIt are used and it
                  is already compiled code.
                  So do you have the source code or not? If you do, find where the exception is being thrown from. It's most likely caused by trying to parse a number out of a String that doesn't contain a number. Figure out how the String you are trying to parse could contain a non-number, and reproduce that.
                  • 6. Re: NumberFormatException plz help...
                    796447
                    I have the source code.
                    I do not have the line no.Because JIt are used and
                    it
                    is already compiled code.
                    So do you have the source code or not? If you do,
                    find where the exception is being thrown from. It's
                    most likely caused by trying to parse a number out of
                    a String that doesn't contain a number. Figure out
                    how the String you are trying to parse could contain
                    a non-number, and reproduce that.
                    He's passing something to SimpleDateFormat.parse, which in turn ends up invoking Long.parseLong.
                    I tried to reproduce it, trying to parse a date string like "2006//20" for a pattern of "yyyy/MM/dd" (thinking maybe it would see a blank month and try to turn that into a number), but the exception was different than what he is seeing.
                    • 7. Re: NumberFormatException plz help...
                      807607
                      Sounds like a bug in SimpleDateFormat to me. It's probably incorrectly handling a malformatted date string. If you have code where SimpleDateFormat parses a date string that may not be correctly formatted (user input, config file, whatever), you should surround it with a try/catch like:
                      try{
                          myDateFormat.parse(dateString);
                      } catch(java.text.ParseException e){
                          //Handle error here
                      }
                      • 8. Re: NumberFormatException plz help...
                        800323
                        He's passing something to SimpleDateFormat.parse,
                        which in turn ends up invoking Long.parseLong.
                        I tried to reproduce it, trying to parse a date
                        string like "2006//20" for a pattern of "yyyy/MM/dd"
                        (thinking maybe it would see a blank month and try to
                        turn that into a number), but the exception was
                        different than what he is seeing.
                        Yeh, that's what I thought. I wanted to see if he could find the exact code and add a display of the String before parsing it.