+ Reply to Thread
Results 1 to 2 of 2

Thread: Error converting string to int

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    28

    Error converting string to int

    I am sometimes getting error converting String to int , here is my code
    Code:
    String text=request.getParameter("some_string");
    int i;
    i=Integer.parseInt(text)
    So what`s wrong ? Because somestimes it works and sometimes not.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    9
    Your parameter might be null , so you always have to check whether it is null or not
    so here you go
    Code:
    String text=request.getParameter("some_thing");
    int i=0;
    if(text!=null){
       try{
         i=Integer.parseInt(text);
       }catch(Exception ex) { 
         out.println(ex);
       }
    }
    If you faced any not understandable error , just paste it here.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

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