1 2 Previous Next 18 Replies Latest reply: May 22, 2007 4:53 AM by 807606 RSS

    NumberFormatException

    807606
      Hi

      I understand that this error msg "java.lang.NumberFormatException" means that we are trying to pass a String value into a int?

      However, I need to pass a String value because the value is actually a password of a database that i need to connect to

      Kindly advise if there is any way to work around this?

      This is my exact error msg :
      java.lang.NumberFormatException: For input string: "itrade4321"
      Kindly assist/advise~! Thanks :)
        • 1. Re: NumberFormatException
          807606
          Why are you trying to parse the String into a number ?
          • 2. Re: NumberFormatException
            807606
            check ur storing variable is in int... if yes change that datatype to String..



            ex:

            String itrade4321;

            not to int itrade4321;
            • 3. Re: NumberFormatException
              807606
              Kindly advise if there is any way to work around
              this?
              I would kindly advise you to change the code (?) that expects a number as input, while passwords are not limited to numbers.
              • 4. Re: NumberFormatException
                807606
                Maybe what you want to do is calculate an Integer value based on your String?
                However your String "itrade4321" is 10 bytes long, and can not be stored as a single Integer value without some data loss. You could store it in three integers or a byte array.
                • 5. Re: NumberFormatException
                  807606
                  yup... i've declared the variable as String

                  btw this is the part of my code where it caught that exception
                     public static void main(String args[]) {
                          FillAlerter ma;
                          try {
                              ma = new FillAlerter("config.xml");
                                      ma.poll();       
                          } catch (Exception ex) {
                              System.out.println ("Exception error! error msg: "+ex.toString());
                          }
                  
                      }
                  btw the config.xml file is actually where i store 'itrade4321' and other info like username etc

                  Thanks
                  • 6. Re: NumberFormatException
                    807606
                    Maybe what you want to do is calculate an Integer
                    value based on your String?
                    However your String "itrade4321" is 10 bytes long,
                    and can not be stored as a single Integer value
                    without some data loss. You could store it in three
                    integers or a byte array.
                    I think u might be right... There is some error msg that points me to byte... i try it out 1st.... will update here again
                    • 7. Re: NumberFormatException
                      807606
                      Your exception is being thrown somewhere within the FillAlerter class. Which line causes the problem:
                      ma = new FillAlerter("config.xml");
                      or
                      ma.poll();
                      If you post the corresponding method it might be easier to understand what you're trying to do.
                      • 8. Re: NumberFormatException
                        807606
                        hi
                        this is poll()
                             public void poll(){
                                startPoll = true;
                                Thread pollThread=null;
                                
                                while(startPoll){
                                    try{
                                         
                                         Thread.sleep(poll);
                                         eventlog.writeln("Start poll");
                                        
                                        trigger();
                        
                                    }catch(Exception e){
                                         eventlog.writeln("[Error] "+e.toString());
                                        e.printStackTrace(eventlog.getWriter());
                                        exlog.writeln("[Error] "+e.toString());
                                        e.printStackTrace(exlog.getWriter());
                                    }
                                }
                        destroy();
                        }
                        Message was edited by:
                        peachtea
                        • 9. Re: NumberFormatException
                          807606
                          Your exception is being thrown somewhere within the
                          FillAlerter class. Which line causes the problem:
                          ma = new FillAlerter("config.xml");
                          or
                          ma.poll();
                          If you post the corresponding method it might be
                          easier to understand what you're trying to do.
                          btw, i try to do a try... catch at each of the statementd... apparently both statements also return the same exception msg
                          hth
                          • 10. Re: NumberFormatException
                            807606
                            Peachtea,

                            You have to drill further down into your code to find the piece that tries to make the number conversion.
                            • 11. Re: NumberFormatException
                              807606
                              Hi GJosef

                              It seems that the fault lies in the FillAlerter()

                              i have added this small segment into FillAlerter()
                                            String password = "itrade4321";
                                            byte[] pass = password.getBytes("itrade4321");
                                            byte[] defaultByte = password.getBytes();
                              and now it produces java.io.UnsupportedEncodingException: itrade4321

                              erm... is that the right way to convert the "itrade4321 into a byte array? o.o

                              Thanks again for your help :)
                              • 12. Re: NumberFormatException
                                807606
                                try {
                                     String password = "itrade4321";
                                     byte[] pass = password.getBytes("UTF-8");
                                     byte[] defaultByte = password.getBytes();
                                } catch (UnsupportedEncodingException e) {
                                     e.printStackTrace();
                                }

                                Alter your code to above.It will work.

                                One more thing the out put of second and third lines will be same.
                                the mistake which you did is that instead of of giving charset as input to the second line you gave the password string again

                                the signature is of that method is

                                public byte[] getBytes(String charsetName)
                                throws UnsupportedEncodingException

                                Where charset values may be

                                US-ASCII,ISO-8859-1 ,UTF-8,UTF-16BE,UTF-16LE,UTF-16
                                • 13. Re: NumberFormatException
                                  807606
                                  Hi there

                                  I put that source code at the place where it is before creating the connection to database (main java file)
                                  I also tried putting in it another java file (that take cares of database connection with info like userid n password)

                                  either way, i still got the same problem :(
                                  One more thing the out put of second and third lines
                                  will be same.
                                  the mistake which you did is that instead of of
                                  giving charset as input to the second line you gave
                                  the password string again

                                  the signature is of that method is

                                  public byte[] getBytes(String charsetName)
                                  throws UnsupportedEncodingException
                                  Sorry can u explain more on the mistake i made? I googled form somewhere that charset is actually a jar file that needs to be copied n paste to classpath right? What do u mean by signaure of method? How do i use it?

                                  Many thanks in advance for your reply!
                                  • 14. Re: NumberFormatException
                                    807606
                                    Are you getting UnsupportedEncodingException now?

                                    signature defines how that method has to be called like
                                    the name of the method,input arguments,argument type etc.

                                    Can you share the code by which you are trying to open the database connection.the way you are passing the password,username,sid,etc and what databse are you using
                                    1 2 Previous Next