0 Replies Latest reply: Feb 18, 2008 9:51 AM by 843851 RSS

    problem with Integer.parseInt

    843851
      Hi all,

      Im currently working on a project and im having problems with Integer.parseInt. I can print the string out fine, but when i convert to an integer, my code throws an error. Please could one you guys pass comment if you can see any mistakes. I think the string possibly has a space in it and this is throwing the error. How could i detect this?

      Look forward to your advice.

      Elvis.
      public class ATListener implements ATCommandListener
           {
                public void ATEvent(String arg0) 
                {
                    String portval;   
                    int count = 0;    
                                        
                  try
                  {
                     
                       if(arg0.indexOf("^SSCNT")>=0) 
                       {
                           portval = arg0.substring(arg0.indexOf(":") + 2);  //Get new value 
                           portval = portval.substring(2, portval.indexOf(9));
      
                                                                       /****** An error occurs on the below line *********/           
                           count = Integer.parseInt(portval); 
                                                                       /******************************************************/
                                                                      
                            if(count>2)
                           {
                           
                            sendSMS("Value = " + portval);  
                                            
                           }
                           else
                           {
                              System.out.println("Error"); 
                           }
                                                 
                                                                                    
                      }
                       
                     }
                   
                      catch (MIDletStateChangeException e) 
                   {
                       System.out.println("ATEvent: " + e);  
                       notifyDestroyed();
                     
                   }
                  
                 }
              
                public void RINGChanged(boolean arg0) { }   
                public void DCDChanged(boolean arg0) { }
                public void DSRChanged(boolean arg0) { }
                public void CONNChanged(boolean arg0) {     }